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.