Category Archives: ssl

How to import a private key and certificate into a java keystore

Convert to PEM format via openssl :

openssl pkcs8 -topk8 -nocrypt -in key.pem -inform PEM -out key.der -outform DER
openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER

Import private key and cert via ImportKey class

Import the keystore generated above into your existing keystore :

keytool -v -importkeystore -srckeystore “C:keystore.ImportKey” -destkeystore “C:.keystore”

(optionally you can specify the alias via –srcalias and –destalias, note that an alias is unique within the keystore)

Sources : http://www.agentbob.info/agentbob/79-AB.html, http://java.sun.com/j2se/1.3/docs/tooldocs/win32/keytool.html and http://conshell.net/wiki/index.php/Keytool_to_OpenSSL_Conversion_tips