微信小程序消息推送解密
- 手机
- 2025-08-24 17:27:02

package com.test.main.b2b; import org.apache mons.codec.binary.Base64; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.util.Arrays; /** * @author * @version 1.0 * @description: 解谜微信小程序消息通知 * @date 2025/2/20 15:29 */ public class 支付回调解密 { // EncodingAESKey(消息加密密钥) public static String encodingAesKey = "sdIeXprnCzbVmDIp"; // Encrypt Msg public static String encryptedData = "urMQfiTkA+nLIV/gpAxwQaFurMQfiTkA+nLIV/gpAxwQaFurMQfiTkA+nLIV/gpAxwQaFurMQfiTkA+nLIV/gpAxwQaFurMQfiTkA+nLIV/gpAxwQaFurMQfiTkA+nLIV/gpAxwQaF"; public static void main(String[] args) throws Exception { // 请替换成你的真实数据 String decrypt = decrypt(encryptedData, encodingAesKey); System.out.println(decrypt); } public static String decrypt(String encryptedMsg, String encodingAesKey) throws Exception { // Base64解码密钥(微信EncodingAESKey是Base64编码的) byte[] aesKey = Base64.decodeBase64(encodingAesKey + "="); byte[] original; try { // 设置解密模式为AES的CBC模式 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); // 使用BASE64对密文进行解码 byte[] encrypted = Base64.decodeBase64(encryptedMsg); // 解密 original = cipher.doFinal(encrypted); } catch (Exception e) { e.printStackTrace(); throw new AesException(AesException.DecryptAESError); } String xmlContent; try { // 去除补位字符 byte[] bytes = PKCS7Encoder.decode(original); // 分离16位随机字符串,网络字节序和AppId byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20); int xmlLength = recoverNetworkBytesOrder(networkOrder); xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), "UTF-8"); } catch (Exception e) { e.printStackTrace(); throw new AesException(AesException.IllegalBuffer); } return xmlContent; } // 还原4个字节的网络字节序 static int recoverNetworkBytesOrder(byte[] orderBytes) { int sourceNumber = 0; for (int i = 0; i < 4; i++) { sourceNumber <<= 8; sourceNumber |= orderBytes[i] & 0xff; } return sourceNumber; } }
微信小程序消息推送解密由讯客互联手机栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“微信小程序消息推送解密”