https://blog.csdn.net/qq_44776721/article/details/113701498 java demo 亲测可用
微信退款通知解析req_info报错?代码: public static Map<String, String> decryptMapFromResponseString(String aesKey, String responseString) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bt = aesKey.getBytes(); md.update(bt); String strDes = bytes2Hex(md.digest()); SecretKeySpec key = new SecretKeySpec(strDes.getBytes(), "AES"); Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] base64ByteArr = Base64.decode(responseString); String result = new String(cipher.doFinal(base64ByteArr), "utf-8"); Map<String, String> map = WXPayUtil.xmlToMap(result); return map; } 报错: Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026) at javax.crypto.Cipher.init(Cipher.java:1245) at javax.crypto.Cipher.init(Cipher.java:1186) at com.hct.lottery.payment.main.pay.weixin.WeixinUtil.decryptMapFromResponseString(WeixinUtil.java:265) at com.hct.lottery.payment.main.pay.weixin.WeixinUtil.main(WeixinUtil.java:338) 什么情况呢?查了半天也没查出来问题,唉!
2021-02-05https://blog.csdn.net/qq_44776721/article/details/113701498 java demo 亲测可用
关于微信支付退款req_info字段解密问题退款成功后退款通知回调req_info字段是加密的 现在通过文档进行base64解码 MD5加密之后进行 key*对加密串B做AES-256-ECB解密(PKCS7Padding)这一步的时候一直报 javax.crypto.BadPaddingException: pad block corrupted 这个错 百度了一堆方法尝试玩还是报这个错 有没有大佬有解决方案的 demo也只有PHP的 也是无语了
2021-02-05https://blog.csdn.net/qq_44776721/article/details/113701498 java demo,亲测可用
退款通知req_info解码乱码?[图片] 网上说要换jre,jre换了程序蹦了咋办呢,要不要这么麻烦呀。怎么解决呀,官方大佬们
2021-02-05https://blog.csdn.net/qq_44776721/article/details/113701498 java demo,亲测可用
退款结果通知解密req_info失败,麻烦看看代码有错误吗?/** * 对微信的返回数据进行解密 做AES-256-ECB解密(PKCS7Padding) * @param encrypted 目标密文 * @param aesKey 解密密钥 * @param * @throws Exception */ public static String decryptWXReturn(String encrypted, String aesKey){ try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","BC"); //这里是不是这样写? //对秘钥进行MD5编码 //这里生成key的方法是错的 Key key = initKeyForAES(MD5Util.encode(aesKey).toLowerCase().toString()); //这才是生成key的正确方法 SecretKeySpec key = new SecretKeySpec(MD5Utils.MD5Encode(aesKey,"UTF-8").toLowerCase().toLowerCase().getBytes(), "AES"); //对秘钥进行MD5加密的时候必须指定UTF-8编码,这样写也是不行的 SecretKeySpec key = new SecretKeySpec(MD5Util.encode(aesKey).toLowerCase().toLowerCase().getBytes(), "AES"); //这样也会报错 cipher.init(Cipher.DECRYPT_MODE, key); byte[] encryptedBase64 = new BASE64Decoder().decodeBuffer(encrypted); byte[] decbbdt = cipher.doFinal(encryptedBase64); //到这一步就开始报错pad block corrupted return new String(decbbdt,"UTF-8"); } catch (Exception e) { logger.error(e); } return null; } public static Key initKeyForAES(String key) throws NoSuchAlgorithmException { if (null == key || key.length() == 0) { throw new NullPointerException("key not is null"); } SecretKeySpec key2 = null; SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(key.getBytes()); try { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(256, random); //这里到底是128还是256??但是两种试了还是报错pad block corrupted //kgen.init(128, random); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); key2 = new SecretKeySpec(enCodeFormat, "AES"); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException(); } return key2; } 秘钥是一致的,这个AES-256-ECB解密(PKCS7Padding)到底怎么解啊,请问代码有问题吗
2021-02-052021了,各位老板这个问题解决了吗
微信支付退款通知中的加密串req_info如何解密?1)官方的文档和demo没有提供了方法? 2)搞这么复杂干什么,多此一举 3)网上搜的那些方法基本不能用。 我用的是java,在mac 电脑上调试。
2021-02-05