我想从PKCS#12文件中提取公钥和私钥,以便以后在SSH-Public-Key-Authentication中使用。
现在,我通过ssh-keygen生成密钥,我把它放在。ssh/authorized_key中,分别放在客户端的某个地方。
以后,我想使用PKCS#12容器中的密钥,因此我必须首先从PKCS#12中提取公钥,然后将它们放入.ssh/authorized_keys文件中。有没有机会让这个工作通过openssl?PKCS#12中的密钥是否与ssh-public-key身份验证兼容?
解决方案1:
从jks中提取P12
keytool -importkeystore -srckeystore MyRootCA.jks -destkeystore MyRootCA.p12 -deststoretype PKCS12
从P12文件中提取PEM,从crt文件中编辑文件和PEM
openssl pkcs12 -in MyRootCA.p12 -clcerts -nokeys -out MyRootCA.crt
从jks中提取密钥
openssl pkcs12 -in MyRootCA.p12 -nocerts -out encryptedPrivateKey.pem
openssl rsa -in encryptedPrivateKey.pem -out decryptedPrivateKey.key
解决方案2:
将PEM和encryptedPrivateKey提取到txt文件' ' '
openssl pkcs12 -in MyRootCA.p12 -out keys_out.txt
解密privateKey
openssl rsa -in encryptedPrivateKey.key [-outform PEM] -out decryptedPrivateKey.key