且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从PKCS12文件中提取公钥/私钥,以供以后在SSH-PK-Authentication中使用

更新时间:2023-01-18 15:48:46

您可以使用以下命令从PKCS#12容器中提取公钥/私钥:

  • PKCS#1私钥

    openssl pkcs12 -in yourP12File.pfx -nocerts -out privateKey.pem
    

  • 证书:

    openssl pkcs12 -in yourP12File.pfx -clcerts -nokeys -out publicCert.pem
    

I want to extract the public and private key from my PKCS#12 file for later use in SSH-Public-Key-Authentication.

Right now, I'm generating keys via ssh-keygen which I put into .ssh/authorized_key, respective somewhere on the client-side.

In future, I want to use the keys from a PKCS#12 container, so I've to extract the public-key first from PKCS#12 and then put them into the .ssh/authorized_keys file. Is there any chance to get this working via openssl? Are the keys in PKCS#12 compatible for ssh-public-key authentication?

You can use following commands to extract public/private key from a PKCS#12 container:

  • PKCS#1 Private key

    openssl pkcs12 -in yourP12File.pfx -nocerts -out privateKey.pem
    

  • Certificates:

    openssl pkcs12 -in yourP12File.pfx -clcerts -nokeys -out publicCert.pem