吐了,终于把微信退款的req_info解密出来了,这里留给别人参考(java)。
发布于 4 年前 作者 gaona 744 次浏览 来自 分享
  1. 当java报错 JCE cannot authenticate the provider BC
    需要引入jar包,在pom文件中加入
<dependency>
     <groupId>org.bouncycastle</groupId>
     <artifactId>bcprov-jdk15on</artifactId>
     <version>1.59</version>
</dependency>
  1. 解密过程
 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);
        }
    }
1 回复

需要替换jre之类的东西吗?

回到顶部