在Java中将JKS转换为P12 [英] Convert jks to p12 in Java

查看:728
本文介绍了在Java中将JKS转换为P12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中将jks文件转换为p12文件,而不是在cmd或openssl中使用keytool.

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();

这就是我创建jks文件的方式.但是我没有找到有关如何将其转换为任何东西的任何信息.谁知道解决方案?谢谢您的回答!

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!

推荐答案

您必须

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.

另外,正如Dave在评论中提到的那样,对目标密钥库使用显式的getInstance("PKCS12").

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

这篇关于在Java中将JKS转换为P12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆