简体   繁体   English

在 Java 中将 jks 转换为 p12

[英]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.我想在 Java 中将 jks 文件转换为 p12 文件,而不是在 cmd 或 openssl 中使用 keytool。

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.这就是我创建 jks 文件的方式。 But I did not find any information about how to convert it to anything.但是我没有找到有关如何将其转换为任何内容的任何信息。 Who does know a solution?谁知道解决办法? Thanks for every answer!感谢您的每一个回答!

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.您必须枚举KeyStore中的别名,并在目标密钥库上为您从源密钥库中获取的每个Entry执行setEntry()

Also, as mentioned by Dave in the comment, use explicit getInstance("PKCS12") for the target key store.此外,正如 Dave 在评论中提到的,对目标密钥存储使用显式getInstance("PKCS12")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM