Ejemplo n.º 1
0
        private static void ValidateSignatureDemo2()
        {
            var pwd             = "123456";
            var signatureParams = new Dictionary <string, string>();
            var timestamp       = SignatureUtils.GetTimestamp().ToString();

            signatureParams.Add("merchant_name", "testaccount");
            signatureParams.Add("signature_method", "SHA1");
            signatureParams.Add("timestamp", timestamp);
            signatureParams.Add("method", "testmethod");
            signatureParams.Add("phone", "13012345678");

            var signOpt = new SignatureOptions()
            {
                IsEncryptPwd   = true,
                PwdEncryptMode = EncryptMode.SHA256,
                Method         = SignatureMethod.SHA1
            };

            var signStr = $"merchant_name=testaccount&method=testmethod&phone=13012345678&signature_method=SHA1&timestamp={timestamp}{CryptographyUtils.SHA256Encrypt(pwd)}";
            var sign    = CryptographyUtils.SHA1Encrypt(signStr);

            Console.WriteLine("signature=" + sign);

            var result = SignatureUtils.ValidateSignature(sign, signatureParams, pwd, "&", new SignatureValidateOptions()
            {
                IsCheckTimestamp   = true,
                TimestampError     = new TimeSpan(0, 5, 0),
                TimestampParamName = "timestamp",
                SignatureOptions   = signOpt
            });

            Console.WriteLine(result);
        }
Ejemplo n.º 2
0
        private static void SHA1EncryptDemo()
        {
            var original = "This is SHA1 Encrypt Demo.";
            var result   = CryptographyUtils.SHA1Encrypt(original);

            Console.WriteLine(result);
            if (result.Equals("c6a7de180d28dd6825e6e0eab80ac8ab5fe4eb7f", StringComparison.CurrentCultureIgnoreCase))
            {
                Console.WriteLine("true");
            }
        }