user1834664
user1834664

Reputation: 451

Convert X509certificate to PKCS12

I am new to java security field. I went through all possible thread to find my answer but to no use. I have X509Certificate and i need to convert this certificate into PKCS12 format. How do i achieve this using java api. any code snippet would be helpful.

Upvotes: 2

Views: 2105

Answers (2)

Rein
Rein

Reputation: 478

Since I find Java KeyTool haunting to use, we use KeyStore Explorer (https://keystore-explorer.org/) to view/create/alter Java KeyStores. To achieve what you want, you can create a new PKCS12 keystore and import the X509 certificate.

Upvotes: 1

mzzzzb
mzzzzb

Reputation: 1452

Assuming that you already have your private key entry in a PKCS12 keystore, you can use keytool with -importcert command. It should look something like

keytool -importcert -file <certificate.cer> -keystore <keystore.p12> -storetype pkcs12 -alias <alias>

details for usage of keytool at http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/keytool.html

If you have your private key in a JKS keystore instead, you might first need to import that entry into a PKCS12 store using -importkeystore

keytool -importkeystore -srckeystore abc.jks -destkeystore abc.p12 -deststoretype pkcs12

when you give a non existent file as destkeystore, a new one will be created.

Upvotes: 0

Related Questions