コード例 #1
0
ファイル: SignatureUtils.cs プロジェクト: junjie-sun/XUtility
        /// <summary>
        /// 生成签名
        /// 签名格式:paramKey1=paramValue分隔符paramKey2=paramValue分隔符paramKey3=paramValuePwd
        /// paramKey以升序排列
        /// </summary>
        /// <param name="signatureParams"></param>
        /// <param name="pwd"></param>
        /// <param name="splitStr"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string GenerateSignature(IDictionary <string, string> signatureParams, string pwd = null, string splitStr = null, SignatureOptions options = null)
        {
            options = options ?? SignatureOptions.GetDefaultOptions();

            if (!string.IsNullOrWhiteSpace(pwd) && options.IsEncryptPwd)
            {
                pwd = Encrypt(pwd, options.PwdEncryptMode);
            }

            SortedDictionary <string, string> data = new SortedDictionary <string, string>();

            if (signatureParams != null)
            {
                foreach (var key in signatureParams.Keys)
                {
                    var param = signatureParams[key];
                    data.Add(key, param);
                }
            }
            var signStr = ComboString(data, pwd, splitStr);

            switch (options.Method)
            {
            case SignatureMethod.MD5:
                return(CryptographyUtils.MD5Encrypt(signStr));

            case SignatureMethod.SHA1:
                return(CryptographyUtils.SHA1Encrypt(signStr));

            default:
                return(CryptographyUtils.MD5Encrypt(signStr));
            }
        }
コード例 #2
0
ファイル: SignatureUtils.cs プロジェクト: junjie-sun/XUtility
        private static string Encrypt(string text, EncryptMode mode)
        {
            switch (mode)
            {
            case EncryptMode.MD5:
                return(CryptographyUtils.MD5Encrypt(text));

            case EncryptMode.SHA1:
                return(CryptographyUtils.SHA1Encrypt(text));

            case EncryptMode.SHA256:
                return(CryptographyUtils.SHA256Encrypt(text));

            case EncryptMode.SHA384:
                return(CryptographyUtils.SHA384Encrypt(text));

            case EncryptMode.SHA512:
                return(CryptographyUtils.SHA512Encrypt(text));

            default:
                return(text);
            }
        }