user12465043
user12465043

Reputation:

Convert jks to p12 in Java

Instead of using keytool in cmd or openssl, I want to convert a jks file to a p12 file in Java.

My code so far is this:

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

char[] password = "lol".toCharArray();
ks.load(null, password);

FileOutputStream fos = new FileOutputStream("C:\\Users\\Antonio\\Desktop\\jkstest\\test.jks");
ks.store(fos, password);
fos.close();

Thats how I create a jks file. But I did not find any information about how to convert it to anything. Who does know a solution? Thanks for every answer!

Upvotes: 0

Views: 1007

Answers (1)

wilx
wilx

Reputation: 18228

You have to enumerate aliases in the source KeyStore and do setEntry() on the target key store for each Entry that you get from the source key store.

Also, as mentioned by Dave in the comment, use explicit getInstance("PKCS12") for the target key store.

Upvotes: 1

Related Questions