吐了,终于把微信退款的req_info解密出来了,这里留给别人参考(java)。
- 当java报错
JCE cannot authenticate the provider BC
需要引入jar包,在pom文件中加入
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.59</version>
</dependency>
- 解密过程
public static String decryptRefundNotifyToString(String reqInfo,String apiKey)
throws GeneralSecurityException, IOException {
try {
Security.addProvider(new BouncyCastleProvider());
String apiKeyMD5 = MD5Util.encode(apiKey).toLowerCase();
SecretKeySpec key = new SecretKeySpec(apiKeyMD5.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","BC");
cipher.init(Cipher.DECRYPT_MODE,key);
return new String(cipher.doFinal(Base64.getDecoder().decode(reqInfo)), StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new IllegalStateException(e);
}
}