HowTo: Create pkcs12 keystore from existing Certificate and Privatekey

Posted on Updated on

The PKCS#12 or PFX format is a binary format for storing the server certificate, any intermediate certificates, and the private key into a single encryptable file. PFX files are usually found with the extensions .pfx and .p12. PFX files are typically used on Windows machines to import and export certificates and private keys.

There are several methods that you can use but I found the following the most simple:

  1. I have Public Certificate and Private key in the folder name /certs



2. Create certificate server.crt is your public certificate and server.key is the private key used to create the keystore server.p12

openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 

In addition for Java Application some times we have to use the JKS keystore, so it need to import the certificates.

keytool -importkeystore -srckeystore server.p12 -srcstoretype PKCS12 -destkeystore server.jks -deststoretype JKS