官方.Net解密方法
public class AesGcm
{
private static string ALGORITHM = "AES/GCM/NoPadding";
private static int TAG_LENGTH_BIT = 128;
private static int NONCE_LENGTH_BYTE = 12;
private static string AES_KEY = "qrmmdt198611qrmmdt198611qrmmdt19";
public static string AesGcmDecrypt(string content, string key, string ivs)
{
byte[] bytes = Encoding.UTF8.GetBytes(key);
byte[] bytes2 = Encoding.UTF8.GetBytes(ivs);
byte[] array = Convert.FromBase64String(content);
byte[] bytes3 = Encoding.UTF8.GetBytes("certificate");
GcmBlockCipher gcmBlockCipher = new GcmBlockCipher(new AesEngine());
AeadParameters aeadParameters = new AeadParameters(new KeyParameter(bytes), 128, bytes2, bytes3);
gcmBlockCipher.Init(false, aeadParameters);
byte[] array2 = new byte[gcmBlockCipher.GetOutputSize(array.Length)];
int num = gcmBlockCipher.ProcessBytes(array, 0, array.Length, array2, 0);
gcmBlockCipher.DoFinal(array2, num);
return Encoding.UTF8.GetString(array2);
}
}
回调内容:
{"id":"1d832905-6b41-5740-bfc2-90578d17887c","create_time":"2020-01-19T12:13:16+08:00","event_type":"PAYSCORE.USER_CONFIRM","resource_type":"encrypt-resource","resource":{"algorithm":"AEAD_AES_256_GCM","ciphertext":"nLUWcQpwQYOnq2QfBNxGfbO+jyvR7WA+up7iW/mv6hZ5VfPUzRB/WSOP6NgrcC+sFSijgtiIGiH/OWvoTifsROvRDqLMjPGfImQ22krvaR8Ydk/K9bNjkv8FAxjn2JMT7aB13E6Y3GCSRxLiudFLVKw4EE6zquyqY9+fsVujzzbHSUDy8DF3ywB9sPx34HlzwA/TWEjA5qzh5xitai68ZGvDekBp6BU4CQ9agvvPBj2OC4fGiJVBQtiEsChKFzzGxVXpB9HswLKROGPKtEE4+C5urLNes5tFQRYWeAsVD5Ipok56ZruvKov1ieWmpL6YOcmK8lEk/NHJkOCPunzPXzrNcUAnBs1iUQXSP431cVLXKVDK92UPscNK5QGLH7i8xEyRs+mg/QPIZ2Yk+vZ7jSOlDCM+HGyQeNaraSwDct8ZpDKpzz28QdWaTLJ7+MQCdURPaSInJ+E9E1HWAPxVwJrtAkJC3Jz83rnC+NMWbtWtzKlRyZchDa02nqUim+Y+Q1JufhDrIx0hjToEJUkqnHfBrmpDbZ0uEn7E5xlqdR9xddJe0YJaY5MlmI/nHKReLqT3rZwxAz9iW78co2xqJNxlD5O35m/L5M+4lrdSeO3JTowjtiQnmqLG30vBrWWMrjJa1sdoKT+Coi8sSllptCpDE8wVFvDW/pXkSLzuZ0TOR3EwmPkwwGxUetczi++xktTmM1OkZ7SedV/5CDpPiSynuZ6G6E3ONK/eTzIUzsopv1HgV3ae0+RIK8TuA9dwFm2jDx0fWnABKa0xLEWC7okitpIHQziTL2ncN+/GabZGQ4XCRO594BujHVDKQDxhYzCM0d6T+j642gJv4DGOlCt8UdlNhl3vc558vMFeuaKJmg10oYHgVG7yaSNGYoi7sfzl8F6N/F3dxm8dqe1kaKk0zbuNRi/o0ilkeAqaYpOgUtvZepwsrGwOdIEyS5zlZCeZ8rAxDP8W/raweDo3jCJp/ts8Y/BHsdX0Y/K7EsbRPAXa","associated_data":"payscore","nonce":"aHAMIh2xWa1o"}}
//回调内容里面的:resource.ciphertext
var content="nLUWcQpwQYOnq2QfBNxGfbO+jyvR7WA+up7iW/mv6hZ5VfPUzRB/WSOP6NgrcC+sFSijgtiIGiH/OWvoTifsROvRDqLMjPGfImQ22krvaR8Ydk/K9bNjkv8FAxjn2JMT7aB13E6Y3GCSRxLiudFLVKw4EE6zquyqY9+fsVujzzbHSUDy8DF3ywB9sPx34HlzwA/TWEjA5qzh5xitai68ZGvDekBp6BU4CQ9agvvPBj2OC4fGiJVBQtiEsChKFzzGxVXpB9HswLKROGPKtEE4+C5urLNes5tFQRYWeAsVD5Ipok56ZruvKov1ieWmpL6YOcmK8lEk/NHJkOCPunzPXzrNcUAnBs1iUQXSP431cVLXKVDK92UPscNK5QGLH7i8xEyRs+mg/QPIZ2Yk+vZ7jSOlDCM+HGyQeNaraSwDct8ZpDKpzz28QdWaTLJ7+MQCdURPaSInJ+E9E1HWAPxVwJrtAkJC3Jz83rnC+NMWbtWtzKlRyZchDa02nqUim+Y+Q1JufhDrIx0hjToEJUkqnHfBrmpDbZ0uEn7E5xlqdR9xddJe0YJaY5MlmI/nHKReLqT3rZwxAz9iW78co2xqJNxlD5O35m/L5M+4lrdSeO3JTowjtiQnmqLG30vBrWWMrjJa1sdoKT+Coi8sSllptCpDE8wVFvDW/pXkSLzuZ0TOR3EwmPkwwGxUetczi++xktTmM1OkZ7SedV/5CDpPiSynuZ6G6E3ONK/eTzIUzsopv1HgV3ae0+RIK8TuA9dwFm2jDx0fWnABKa0xLEWC7okitpIHQziTL2ncN+/GabZGQ4XCRO594BujHVDKQDxhYzCM0d6T+j642gJv4DGOlCt8UdlNhl3vc558vMFeuaKJmg10oYHgVG7yaSNGYoi7sfzl8F6N/F3dxm8dqe1kaKk0zbuNRi/o0ilkeAqaYpOgUtvZepwsrGwOdIEyS5zlZCeZ8rAxDP8W/raweDo3jCJp/ts8Y/BHsdX0Y/K7EsbRPAXa";
//微信商户平台的支付密钥
var key="qrmmdt198611qrmmdt198611qrmmdt19";
//回调内容里面的:nonce
var ivs="aHAMIh2xWa1o";
//调用官网解密方法
AesGcm.AesGcmDecrypt(content, key, ivs)
是我传的参数写错了吗??
{
"appid": "wx401feb9d847127e2",
"mchid": "1519974821",
"service_id": "00002000000000157725521635280204",
"out_order_no": "63405392bd6e7f30",
"service_introduction": "充吖共享充电宝",
"state": "DOING",
"state_description": "USER_CONFIRM",
"total_amount": 0,
"post_payments": [{
"name": "租借费用",
"description": "3元/每小时,租借5分钟免费,日封顶30元."
}],
"risk_fund": {
"name": "DEPOSIT",
"amount": 9900,
"description": "共享充电宝押金费用"
},
"time_range": {
"start_time": "20200119121411"
},
"location": {
"start_location": "广州番禺万达三介科技"
},
"attach": "",
"notify_url": "https://con.sualianpay.com/loTApi/LotPayCallBack",
"order_id": "1000000000202001191098081680168",
"need_collection": true,
"openid": "orYRa5L3iwMCMoeZ0cEdgde0S1rs"
}
解析成功
//AesGcm.AesGcmDecrypt("payscore", ivs, content)
参看解密文档https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/zheng-shu-he-hui-tiao-bao-wen-jie-mi