微信退款回调解密 pad block corrupted

2020-04-11 14:40:48 +08:00
 zhongjianrong

以下是相关代码

public static String decryptData(String base64Data) throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
    cipher.init(Cipher.DECRYPT_MODE, key);
    byte[] decode = Base64Util.decode(base64Data);
    return new String(cipher.doFinal(decode));
}

public static byte[] decode(String data) {  
    char ibuf[] = new char[4];  
    int ibufcount = 0;  
    byte obuf[] = new byte[(data.length() / 4) * 3 + 3];  
    int obufcount = 0;  
    for (int i = 0; i < data.length(); i++) {  
        char ch = data.charAt(i);  
        if (ch != '=' && (ch >= S_DECODETABLE.length || S_DECODETABLE[ch] == 127))  
            continue;  
        ibuf[ibufcount++] = ch;  
        if (ibufcount == ibuf.length) {  
            ibufcount = 0;  
            obufcount += decode0(ibuf, obuf, obufcount);  
        }  
    }  

    if (obufcount == obuf.length) {  
        return obuf;  
    }  
    else {  
        byte ret[] = new byte[obufcount];  
        System.arraycopy(obuf, 0, ret, 0, obufcount);  
        return ret;  
    }  
}  

    public static String md5Encode(String origin, String charsetname) {
        String resultString = null;  
        try {  
            resultString = new String(origin);  
            MessageDigest md = MessageDigest.getInstance("MD5");  
            if (charsetname == null || "".equals(charsetname))  
                resultString = byteArrayToHexString(md.digest(resultString.getBytes()));  
            else  
                resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));  
        }  
        catch (Exception exception) {  
        }  
        return resultString;  
    }
2131 次点击
所在节点    Java
2 条回复
LemonCoo1
2020-04-11 15:47:55 +08:00
java 推荐这个 https://github.com/Wechat-Group/WxJava 全套的微信 SDK
yidinghe
2020-04-11 15:54:24 +08:00
微信提供了封装好的 WechatPayHttpClientBuilder,直接用吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/661448

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX