I have java code that needs a keystore and I have privateKey.pem and bank.cer file. Private key would be 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With