我有一个使用 bouncycaSTLe 库创建的 X.509 证书。如何将其存储到 java keystore 中?
我尝试了这段代码
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
// get user password and file input stream
char[] password = getPassword();
java.io.FileInputStream fis =
new java.io.FileInputStream("keyStoreName");
ks.load(fis, password);
fis.close();
我找到了这个代码here ,但是使用这种方式创建的 keystore 不适用于 keytool,它告诉我 keystore 已损坏。
最佳答案
使用KeyStore.setCertificateEntry(alias, cert)
并为其指定一个您选择的别名。然后,使用 KeyStore.store(...)
保存 keystore (通常使用 FileOutputStream
)。
关于java - 使用 java 代码将 X.509 证书存储到 keystore 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16219887/