Java 如何将JKS证书/密钥转换为BouncyCastle证书/密钥

Java 如何将JKS证书/密钥转换为BouncyCastle证书/密钥,java,security,bouncycastle,Java,Security,Bouncycastle,在我的java应用程序中,我有一个带有自签名证书/密钥的JKS密钥库。我需要加载它们并将它们转换为BouncyCastle类型 我正在使用java.security.KeyStore加载cert/key,它为我提供java.security.cert.Certificate和java.security.key 然后如何将它们转换为BouncyCastle使用的格式(org.BouncyCastle.asn1.x509.Certificate等) 如果我使用Security.addProvider

在我的java应用程序中,我有一个带有自签名证书/密钥的JKS密钥库。我需要加载它们并将它们转换为BouncyCastle类型

我正在使用java.security.KeyStore加载cert/key,它为我提供java.security.cert.Certificate和java.security.key

然后如何将它们转换为BouncyCastle使用的格式(org.BouncyCastle.asn1.x509.Certificate等)

如果我使用Security.addProvider(新的BouncyCastleProvider());这会使密钥库返回不同的类型吗

或者BC是否有自己的密钥库API(注意:密钥库是JKS/SUN格式的)


谢谢

我弄明白了,这里有一些伪代码

转换证书:

byte data[] = java.security.cert.Certificate.getEncoded();
org.bouncycastle.asn1.x509.Certificate.getInstance(data);
要转换密钥,请执行以下操作:

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