天天看點

如何讓OpenSSL得到JKS格式的keystore中的public and private key

内部邀請碼:C8E245J (不寫邀請碼,沒有現金送)

國内私募機構九鼎控股打造,九鼎投資是在全國股份轉讓系統挂牌的公衆公司,股票代碼為430719,為“中國PE第一股”,市值超1000億元。 

--------------------------------------------------------

從一個JKS的keystore中導出public key (certificate)

keytool -export -alias mykey -keystore keystore -file exported.crt

轉換成PEM格式,這個格式使用更廣

openssl x509 -out exported-pem.crt -outform pem -text -in exported.crt -inform der
javac ExportPriv.java java ExportPriv <keystore> <alias> <password> > exported-pkcs8.key

上述得到的private key是PKCS#8 PEM格式,使用如下指令才能轉換成apache可以使用的RSA格式

openssl pkcs8 -inform PEM -nocrypt -in exported-pkcs8.key -out exported.key

現在可以把得到的public key(certificate) 和private key打包在一起,轉換成windows平台常用的PKCS12格式

openssl pkcs12 -export -out exported.pfx -inkey exported.key -in exported-pem.crt