开发者

Creating a keystore from private key and a public key

开发者 https://www.devze.com 2023-03-11 13:23 出处:网络
I have java code that needs a keystore and I have privateKey.pem and bank.cer file. Private key would b开发者_如何学Ce to sign a value to bank and bank.cer to verify banks response. I can\'t find a wa

I have java code that needs a keystore and I have privateKey.pem and bank.cer file. Private key would b开发者_如何学Ce to sign a value to bank and bank.cer to verify banks response. I can't find a way to put them into a keystore so my code would work.

Can it be done with keytool?


From my understanding it's impossible to do this with keytool alone. I use openssl for preparation.

Suppose the key is in file key and the certificate is in a file cert. You have to create a PKCS12 file that contains both (because keytool can handle PKCS12 and JKS and I don't know if anything else):

openssl pkcs12 -inkey key -in cert -export -out keys.pkcs12

Now you can import that into a keystore:

keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore mykeystore

This approach worked for me where everything else failed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号