使用java8 java7 java6 解密微信小程序encryptedData能夠回遇到一些錯誤java
1.java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/CBC/PKCS7Padding小程序
2.Java.security.NoSuchProviderException: no such provider: BC 微信小程序
解決方法:微信
1.下載bcprov-jdk15on:jar,下再地址:http://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.58session
2.解密代碼ide
static{
Security.addProvider(new BouncyCastleProvider());
}人工智能
// 被加密的數據
byte[] dataByte = Base64.decodeBase64(encryptedData);
// 加密祕鑰
byte[] keyByte = Base64.decodeBase64(sessionkey);
// 偏移量
byte[] ivByte = Base64.decodeBase64(iv);
try {
// Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding","BC");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding","BC");
SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
parameters.init(new IvParameterSpec(ivByte));
cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
byte[] resultByte = cipher.doFinal(dataByte);
if (null != resultByte && resultByte.length > 0) {
String result = new String(resultByte, "UTF-8");加密
}.net
result 就是解密的數據3d
分享一個朋友的人工智能教程。零基礎!通俗易懂!風趣幽默!你們能夠看看是否對本身有幫助,點擊查看教程。
若是對你有幫助,請不吝打賞