java - 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 证书。
有人遇到过这个问题吗?任何额外的信息告诉我。
预先感谢,问候。
解决方案
推荐阅读
- python - 将列表形式的 Python 字符串转换为列表
- ruby-on-rails - Brcrypt 验证方法不适用于已经 brcypt 值
- node.js - 在没有ajax的函数中表达中间件
- php - 为什么 Apache 改变请求方法并转向文件路径?
- python - Python:特殊字符转二进制
- aws-lambda - 如何使用 AWS Lamda 函数在本地系统上执行文件
- python-3.x - Difference between these two algorithms
- amazon-web-services - AWS Athena JDBC PreparedStatement
- spring - Rest Template GET 列表和 testBuilder 方法问题 Spring
- spring - 如何使用 Spring JPA Repository 搜索带有撇号的字符串