在我的 java 应用程序中,我有一个带有自签名证书/ key 的 JKS keystore 。我需要加载它们并将它们转换为 BouncyCaSTLe 类型。
我正在使用 java.security.KeyStore 加载证书/ key ,它为我提供了 java.security.cert.Certificate 和 java.security.Key。
如何将它们转换为 BouncyCaSTLe 使用的格式(org.bouncycaSTLe.asn1.x509.Certificate 等)
如果我使用 Security.addProvider(new BouncyCaSTLeProvider());这会让 KeyStore 返回不同的类型吗???
或者 BC 是否有自己的 KeyStore API(注意: keystore 采用 JKS/SUN 格式)。
谢谢
最佳答案
我明白了,这是一些伪代码。
转换证书:
byte data[] = java.security.cert.Certificate.getEncoded();
org.bouncycastle.asn1.x509.Certificate.getInstance(data);
转换 key :
byte data[] = java.securty.Key.getEncoded();
if (isRSA) {
RSAPrivateKey rsa = RSAPrivateKey.getInstance(data);
return new RSAPrivateCrtKeyParameters(rsa.getModulus(), rsa.getPublicExponent(),
rsa.getPrivateExponent(), rsa.getPrime1(), rsa.getPrime2(), rsa.getExponent1(),
rsa.getExponent2(), rsa.getCoefficient());
} else {
return PrivateKeyFactory.createKey(data);
}
关于java - 如何将 JKS 证书/ key 转换为 BouncyCaSTLe 证书/ key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20936196/