Convert jks to p12 in Java

蹲街弑〆低调 提交于 2020-04-30 11:08:28

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/60956214/convert-jks-to-p12-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!