java使用AES-256-ECB(PKCS7Padding)解密——微信支付退款通知接口指定解密方式
1.场景
在做微信支付退款通知接口时,微信对通知的内容做了加密,并且指定用 AES256 解密,官方指定的解密方式如下:
2.导包
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on --> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk15on</artifactId> <version>1.60</version> </dependency> <!-- https://mvnrepository.com/artifact/org.jasypt/jasypt --> <dependency> <groupId>org.jasypt</groupId> <artifactId>jasypt</artifactId> <version>1.9.3</version> </dependency>
3.解密
说明:方法中参数 reqInfo 就是退款结果通知接口中的 req_info 字段值
private String descrypt(String reqInfo) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { byte[] reqInfoB = Base64.decodeBase64(reqInfo); String key_ = DigestUtils.md5Hex(WXPayConfig.getInstance().getKey()).toLowerCase(); if (Security.getProvider("BC") == null){ Security.addProvider(new BouncyCastleProvider()); } Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC"); SecretKeySpec secretKeySpec = new SecretKeySpec(key_.getBytes(), "AES"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); return new String(cipher.doFinal(reqInfoB)); }
4.结果
5.参考
解密方式:https://blog.csdn.net/qq_25958497/article/details/87937020
报错解决(报错内容“No such provider: BC”):https://www.cnblogs.com/wswang/p/7718150.html
相关推荐
浪味仙 2020-08-17
YClimb 2020-09-15
qzzza 2019-09-12
kuaigaoding 2018-03-15
美谷niceValley 2019-03-26
likeconan 2019-06-29
huikawlkj 2019-06-28
zbllilac 2018-11-13
jetamiett 2019-04-26
cugihb 2018-10-26
网上的很多PHP微信支付接入教程都颇为复杂,且需要配置和引入较多的文件,本人通过整理后给出一个单文件版的,希望可以给各位想接入微信支付的带来些许帮助和借鉴意义。直接运行该文件即可给指定的微信用户退款。
PHP二次开发 2018-05-30
xiaoyanyan 2018-03-15
xiaoyanyan 2018-10-01
wukaiyun 2018-10-02