Creating a keystore from private key and a public key
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.
精彩评论