Convert Java Keystore JKS into PEM format

Java Keystore or a JKS file is a store of security certificates ( private keys, signer certificates). The JKS file is created using keytool utility that shipped with JDK. The JKS file format is proprietary and used by Java applications.

Many application on windows uses PEM ( Privacy-Enhance Mail) format for storing and sending certificates and keys. The PEM format is generally used to send the certificate via emails as it is base64 encoded.

We can use keytool command to export key entry into PEM file format.


keytool -exportcert -alias mykey -keystore MyKeystore.jks -rfc -file mykey_cert.pem

After executing the above command the certificate will be exported and stored into mykey_cert.pem file.

By default "keytool -exportcert" command export the certificate as binary encoding i.e Distinguished Encoded Rules (DER) file format. DER format is not suitable for transmitting the certificate file and hence, we need to convert the file as PEM format. The -rfc switch option in the above command export the certificate into printable encoding format.

Comments

Popular posts from this blog

Creating simple Maven multi module project in Java

Tricky Java Questions

How to update existing CCDT file (AMQCLCHL.TAB) for successful MQueue connection