コード例 #1
0
        public void AesDecrypt(string plainText, string key)
        {
            var encrypted = Cryptography.AesEncrypt(plainText, key);

            Assert.IsNotNull(encrypted);

            var decrypted = Cryptography.AesDecrypt(encrypted, key);

            Assert.IsNotNull(decrypted);

            Assert.AreEqual(plainText, decrypted);
        }
コード例 #2
0
        //验证URL
        // @param sMsgSignature: 签名串,对应URL参数的msg_signature
        // @param sTimeStamp: 时间戳,对应URL参数的timestamp
        // @param sNonce: 随机串,对应URL参数的nonce
        // @param sEchoStr: 随机串,对应URL参数的echostr
        // @param sReplyEchoStr: 解密之后的echostr,当return返回0时有效
        // @return:成功0,失败返回对应的错误码
        public static string VerifyURL(int appId, string msgSignature, string timeStamp,
                                       string nonce, string echoStr)
        {
            Tuple <string, string> token = WeixinSettings.Current.GetToken(appId);

            if (VerifySignature(token.Item1, timeStamp, nonce, echoStr, msgSignature))
            {
                string corpId;
                string result = Cryptography.AesDecrypt(echoStr, token.Item2, out corpId);
                return(result);
            }
            return(null);
        }
コード例 #3
0
        // 检验消息的真实性,并且获取解密后的明文
        // @param sMsgSignature: 签名串,对应URL参数的msg_signature
        // @param sTimeStamp: 时间戳,对应URL参数的timestamp
        // @param sNonce: 随机串,对应URL参数的nonce
        // @param sPostData: 密文,对应POST请求的数据
        // @param sMsg: 解密后的原文,当return返回0时有效
        // @return: 成功0,失败返回对应的错误码
        public static string DecryptMsg(CorpEncodeReceiveMessage message, string msgSignature,
                                        string timeStamp, string nonce)
        {
            Tuple <string, string> token = WeixinSettings.Current.GetToken(message.AgentId);

            string encryptMsg = message.Encrypt;

            //verify signature
            if (VerifySignature(token.Item1, timeStamp, nonce, encryptMsg, msgSignature))
            {
                string corpId;
                string sMsg = Cryptography.AesDecrypt(encryptMsg, token.Item2, out corpId);
                return(sMsg);
            }
            return(null);
        }
コード例 #4
0
        public static string DecryptMsg(EncodeReceiveMessage message, string msgSignature,
                                        string timeStamp, string nonce)
        {
            string encryptMsg = message.Encrypt;

            var setting = WeixinSettings.Current;

            //verify signature
            if (WeCorpUtil.VerifySignature(setting.Token, timeStamp, nonce, encryptMsg, msgSignature))
            {
                string appId;
                string sMsg = Cryptography.AesDecrypt(encryptMsg, setting.EncodingAESKey, out appId);
                return(sMsg);
            }
            return(null);
        }