在 java 中将密钥对导入没有证书链的 pfx 文件
import key pair to pfx file without certificate chain in java
//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} 或者如果我通过 新证书[]{} 我'我收到一条错误消息 "Private key must be accompanied by certificate chain".
所以,如果不通过证书链,我如何将密钥对导入 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.
//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} 或者如果我通过 新证书[]{} 我'我收到一条错误消息 "Private key must be accompanied by certificate chain".
所以,如果不通过证书链,我如何将密钥对导入 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.