错误信息: java.lang.SecurityException: JCE cannot authenticate the provider BC
环境描述:
- jdk 11.0.3
- tomcat 8.5.8
加解密依赖hutool
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.4</version>
</dependency>
报错代码:
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
String publicKey = "public key string";
String privateKeyStr = "private key string";
RSA rsa = new RSA(privateKeyStr, publicKey);
String content = "这里是加密后的字符串";
String decryptStr = rsa.decryptStr(content, KeyType.PrivateKey);
System.out.println(decryptStr);
}
解决办法:
添加maven依赖
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.66</version>
</dependency>