Exemplo n.º 1
0
        /// <summary>
        /// 请求头验证
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="content"></param>
        /// <param name="secretKey"></param>
        /// <returns></returns>
        public static bool ValidateSignatureHeader(HttpRequestMessage requestMessage, string content, string secretKey)
        {
            IEnumerable <string> keys;

            requestMessage.Headers.TryGetValues(ConstClass.SIGNATURE_PARA, out keys);
            if (keys.Count() > 0)
            {               //加密方式,MD5(内容+key)
                return(keys.First() == Encryptions.Md5Encryptor32(string.Concat(content, secretKey)));
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 数据包验证
        /// </summary>
        /// <param name="content"></param>
        /// <param name="aesKey"></param>
        /// <returns></returns>

        public static bool ValidateAes(string content, string aesKey, out EncryptionDataModel model)
        {
            model = null;
            try
            {
                if (!string.IsNullOrEmpty(content))
                {
                    string rawContent = Encryptions.AesDecryption(content, aesKey);
                    if (!string.IsNullOrEmpty(rawContent))
                    {
                        model = JsonConvert.DeserializeObject <EncryptionDataModel>(rawContent);
                        return(true);
                    }
                }
            }
            catch
            {
            }
            return(false);
        }