首页 > 解决方案 > BouncyCastle 库 1.59 出错(NoSuchAlgorithmException)

问题描述

我已将 BouncyCastle 库 1.49 更新到版本 1.59,但出现以下错误:

exception unwrapping private key - java.security.NoSuchAlgorithmException: Cannot find any provider supporting 2.16.840.1.101.3.4.1.42

java.io.IOException: exception unwrapping private key - java.security.NoSuchAlgorithmException: Cannot find any provider supporting 2.16.840.1.101.3.4.1.42

        at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.unwrapKey(Unknown Source)

        at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(Unknown Source)

        at java.security.KeyStore.load(KeyStore.java:1226)

实现的代码如下:

KeyStore keystore = KeyStore.getInstance("PKCS12", new BouncyCastleProvider());
keystore.load(new ByteArrayInputStream(hexStringToByteArray(privKey)), passphrase.toCharArray());

Enumeration<String> aliases = keystore.aliases();

String keyAlias = "";

while (aliases.hasMoreElements()) {
    keyAlias = (String) aliases.nextElement();
}

PrivateKey key = (PrivateKey) keystore.getKey(keyAlias, passphrase.toCharArray());
final Cipher cipher = Cipher.getInstance("RSA/NONE/OAEPWithSHA256AndMGF1Padding", new BouncyCastleProvider());

cipher.init(Cipher.DECRYPT_MODE, key);
byte[] arr = hexStringToByteArray(encriptedPin);
byte[] decryptedTextBytes = cipher.doFinal(arr);
return new String(decryptedTextBytes);

我已经更新了 JCE 政策,但它仍然不起作用,以及 .pk8 证书。

有人遇到过这个问题吗?任何额外的信息告诉我。

预先感谢,问候。

标签: javaencryptioncryptographybouncycastlekeystore

解决方案


推荐阅读