Example #1
0
        public static bool Sign(Dictionary <string, string> data, Encoding encoder, string signCertpath, string signCertpwd)
        {
            data["certId"] = CertUtil.GetSignCertId(signCertpath, signCertpwd);
            string str = SignUtil.CoverDictionaryToString(data);

            byte[] numArray = SecurityUtil.Sha1X16(str, encoder);
            string lower    = BitConverter.ToString(numArray).Replace("-", "").ToLower();

            byte[] numArray1 = SecurityUtil.SignBySoft(CertUtil.GetSignProviderFromPfx(signCertpath, signCertpwd), encoder.GetBytes(lower));
            data["signature"] = Convert.ToBase64String(numArray1);
            return(true);
        }
Example #2
0
        public static bool Validate(Dictionary <string, string> data, Encoding encoder, string validateCertdir)
        {
            bool flag;

            byte[] numArray = Convert.FromBase64String(data["signature"]);
            data.Remove("signature");
            byte[] numArray1 = SecurityUtil.Sha1X16(SignUtil.CoverDictionaryToString(data), encoder);
            string lower     = BitConverter.ToString(numArray1).Replace("-", "").ToLower();
            RSACryptoServiceProvider validateProviderFromPath = CertUtil.GetValidateProviderFromPath(data["certId"], validateCertdir);

            flag = (null != validateProviderFromPath ? SecurityUtil.ValidateBySoft(validateProviderFromPath, numArray, encoder.GetBytes(lower)) : false);
            return(flag);
        }
Example #3
0
        /// <summary>
        /// 验证签名
        /// </summary>
        /// <param name="data"></param>
        /// <param name="encoder"></param>
        /// <returns></returns>
        public static bool Validate(Dictionary <string, string> data, Encoding encoder, string validateCertdir)
        {
            string stringData = CoverDictionaryToString(data);
            //获取签名
            string signValue = data["signature"];

            byte[] signByte = Convert.FromBase64String(signValue);
            data.Remove("signature");
            stringData = CoverDictionaryToString(data);
            byte[] signDigest                 = SecurityUtil.Sha1X16(stringData, encoder);
            string stringSignDigest           = BitConverter.ToString(signDigest).Replace("-", "").ToLower();
            RSACryptoServiceProvider provider = CertUtil.GetValidateProviderFromPath(data["certId"], validateCertdir);

            if (null == provider)
            {
                return(false);
            }
            return(SecurityUtil.ValidateBySoft(provider, signByte, encoder.GetBytes(stringSignDigest)));
        }
Example #4
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="dataStr"></param>
        /// <param name="encoder"></param>
        /// <returns></returns>
        public static bool Sign(Dictionary <string, string> data, Encoding encoder, string signCertpath, string signCertpwd)
        {
            //设置签名证书序列号 ?
            data["certId"] = CertUtil.GetSignCertId(signCertpath, signCertpwd);
            //将Dictionary信息转换成key1=value1&key2=value2的形式
            string stringData = CoverDictionaryToString(data);

            string stringSign = null;

            byte[] signDigest = SecurityUtil.Sha1X16(stringData, encoder);

            string stringSignDigest = BitConverter.ToString(signDigest).Replace("-", "").ToLower();

            byte[] byteSign = SecurityUtil.SignBySoft(CertUtil.GetSignProviderFromPfx(signCertpath, signCertpwd), encoder.GetBytes(stringSignDigest));

            stringSign = Convert.ToBase64String(byteSign);

            //设置签名域值
            data["signature"] = stringSign;

            return(true);
        }