V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhongjianrong
V2EX  ›  Java

微信退款回调解密 pad block corrupted

  •  
  •   zhongjianrong · 2020-04-11 14:40:48 +08:00 · 2329 次点击
    这是一个创建于 1705 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以下是相关代码

    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;  
        }
    
    2 条回复    2020-04-11 15:54:24 +08:00
    LemonCoo1
        1
    LemonCoo1  
       2020-04-11 15:47:55 +08:00
    java 推荐这个 https://github.com/Wechat-Group/WxJava 全套的微信 SDK
    yidinghe
        2
    yidinghe  
       2020-04-11 15:54:24 +08:00
    微信提供了封装好的 WechatPayHttpClientBuilder,直接用吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   866 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 21:19 · PVG 05:19 · LAX 13:19 · JFK 16:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.