收藏
回答

.Net版本根据官方解密方法对支付分支付回调数据解密时报错?

官方.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)


是我传的参数写错了吗??

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签