gpt4 book ai didi

java - 在java中将 key 对导入到没有证书链的pfx文件中

转载 作者:行者123 更新时间:2023-11-30 06:15:14 24 4
gpt4 key购买 nike

//Generate key pair
KeyPair pair = keyGen.generateKeyPair();

//Open a keystore
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(null, null);

//Setting a key entry
ks.setKeyEntry("test", pair.getPrivate(), password, **new Certificate[]{cert}**);

如果我通过 null 而不是新证书[]{cert},或者如果我通过新证书[]{},我会收到一条错误消息 “私钥必须附有证书链”

那么,在不传递证书链的情况下,如何将 key 对导入到 pfx 文件中。

最佳答案

虽然 PKCS#12 规范允许存储私钥,但 Java Keystore 不支持在没有证书链的情况下存储私钥

参见KeyStore.setKeyEntry documentation

If the given key is of type java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key.

关于java - 在java中将 key 对导入到没有证书链的pfx文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49359970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com