@Test public void testDecrypt() { String sessionKey = "7MG7jbTToVVRWRXVA885rg=="; String encryptedData = "BY6VOgcWbwGcyrunK0ECWI8rnDsT69DucZ+M78tc1aL9aM/3bEAHFYd4fu7kRjWhD4YfjObw44T9vUqKyHIjbKs6hvtEasZZEIW35x4a91xVgN48ZqZ7MTQqUlP13kDUlkuwYh+/8g8yceu4kNbjowYrhihx+SV7CfjKCveJ7TSepr5Z7aLv1o+rfeelfOwn++WN/YoQsuZ6S3L4fWlWe5DAAUnFUI6cJvxxCohVzbrVXhyH2AqQdSjH2WnMYFeaGFIbcoxMznlk7oEwFn+hBj63dyT/swdYQfEdzuyCBmKXy8d6l1RKVX6Y65coTD8kIlbr+FKsqYrXVUIUBSwehqYuOdhYWZ9Bntl5DWU1oqzAPCnMn2cAIoQpQPKP7IGSxMOvCNAMhVXbE7BvnWuVuGF+AM5tXAa9IVUhcMImGwLQqm4iV5uBd+5OcFObh3A4VJk9iBCBWSkBHa/rV9CVoY0bFv2F9/2Hv82++Ybl274="; String ivStr = "TarMFjnzHVxy8pdS93wQbw=="; System.out.println(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr)); }
public static String decrypt(String sessionKey, String encryptedData, String ivStr) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(Base64.decodeBase64(ivStr))); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), params); return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8); } catch (Exception e) { throw new RuntimeException("AES解密失败！", e); } }
WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { public static String decrypt(String sessionKey, String encryptedData, String ivStr) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(Base64.decodeBase64(ivStr))); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), params); return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8); } catch (Exception e) { throw new RuntimeException("AES解密失败！", e); } } }
WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { public static String decrypt(String sessionKey, String encryptedData, String ivStr) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(Base64.decodeBase64(ivStr))); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), params); return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8); } catch (Exception e) { throw new RuntimeException("AES解密失败！", e); } } WxMaCryptUtils(WxMaConfig config); }
WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { public static String decrypt(String sessionKey, String encryptedData, String ivStr) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(Base64.decodeBase64(ivStr))); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), params); return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8); } catch (Exception e) { throw new RuntimeException("AES解密失败！", e); } } WxMaCryptUtils(WxMaConfig config); static String decrypt(String sessionKey, String encryptedData, String ivStr); static String decryptAnotherWay(String sessionKey, String encryptedData, String ivStr); }
WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { public static String decrypt(String sessionKey, String encryptedData, String ivStr) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(Base64.decodeBase64(ivStr))); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.decodeBase64(sessionKey), "AES"), params); return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8); } catch (Exception e) { throw new RuntimeException("AES解密失败！", e); } } WxMaCryptUtils(WxMaConfig config); static String decrypt(String sessionKey, String encryptedData, String ivStr); static String decryptAnotherWay(String sessionKey, String encryptedData, String ivStr);  }