如何以 PKCS #12 格式导出证书和私钥
可以创建一个 PKCS #12 格式的文件,用于将私钥及其关联的 X.509 证书导出到其他系统。对该文件的访问受口令保护。
找到要导出的证书。
% pktool list
Found number certificates.
1. (X.509 certificate)
Label: label-name
ID: fingerprint that binds certificate to private key
Subject: subject-DN
Issuer: distinguished-name
Serial: hex-serial-number
2. ...
导出密钥和证书。
使用 pktool list 命令生成的密钥库和标签。为导出文件提供文件名。如果文件名包含空格,需要用双引号将其括起来。
% pktool export keystore=keystore outfile=outfile-name label=label-name
使用口令保护导出文件。
在提示符下键入密钥库的当前口令。此时,即会为导出文件创建口令。接收者在导入该文件时必须提供此口令。
Enter pin for Sun Software PKCS#11 softtoken: Type PIN for token
Enter password to use for accessing the PKCS12 file:Create PKCS #12 password
提示 -
将口令与导出文件分开发送。建议的最佳做法是不通过发送数据来提供口令,例如通过打电话。
示例 4-4以 PKCS #12 格式导出证书和私钥
在下面的示例中,用户将私钥及其关联的 X.509 证书导出到一个标准的 PKCS #12 文件中。可将此文件导入到其他密钥库中。PKCS #11 口令可保护源密钥库。PKCS #12 口令用于保护 PKCS #12 文件中的私有数据。导入该文件时需要提供此口令。
% pktool list
No. Key Type Key Len. Key Label
----------------------------------------------------
Asymmetric public keys:
1 RSA My Cert
Certificates:
1 X.509 certificate
Label: My Cert
ID: d2:7e:20:04:a5:66:e6:31:90:d8:53:28:bc:ef:55:55:dc:a3:69:93
Subject: C=US, O=My Company, OU=Security Engineering Group, CN=MyCA
Issuer: C=US, O=My Company, OU=Security Engineering Group, CN=MyCA
Serial: 0x000001
% pktool export keystore=pkcs11 outfile=mydata.p12 label="My Cert"
Enter pin for Sun Software PKCS#11 softtoken: Type PIN for token
Enter password to use for accessing the PKCS12 file:Create PKCS #12 password
然后,用户打电话给接收者,提供 PKCS #12 口令。