Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate PKCS12 file using Java

Tags:

java

jce

pkcs#12

I need to generate a PKCS12 file using Java. Actually, I need to automate the following certificate generation using openssl (the ca was created previously and is not pretended to automate its creation):

openssl genrsa -out client.key 2048

openssl req -new -key client.key -out client.csr

openssl ca -keyfile ca.key -cert ca.crt -out client.crt -policy policy_anything -infiles client.csr

openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12 -name client

I want to know if it's possible to perform this without using Bouncycastle or similar libraries, just only JCE, because I didn't find any info related with the PKCS12 generation.

like image 574
vwfziwl Avatar asked Dec 07 '11 16:12

vwfziwl


People also ask

Is a p12 file a keystore?

p12 is the keystore and -nokeys means only extract the certificates and not the keys.


2 Answers

Creating a PKCS#12 is easy - that can be done by writing KeyStore "PKCS12" instance, add the certificate and keys and then save it to a file using the store(...) method.

The rest is a bit more problematic.

like image 121
Robert Avatar answered Oct 13 '22 01:10

Robert


No problem with creation keypairs and certificates but JCE has no API for signing (this is absolutely, I've spent lots of time searching it). Bouncycatle lib is a right choice.

like image 43
korifey Avatar answered Oct 13 '22 02:10

korifey