Ejemplo n.º 1
0
        private void btn_Verify_Click(object sender, EventArgs e)
        {
            String result = String.Empty;
            String sign   = textBox_Sign.Text.Trim(),
                   body   = textBox_Body.Text.Trim();

            if (String.IsNullOrEmpty(sign))
            {
                MessageBox.Show("签名不能为空!", "温馨提示");
                return;
            }

            if (String.IsNullOrEmpty(body))
            {
                MessageBox.Show("待处理文本不能为空!", "温馨提示");
                return;
            }

            try
            {
                var b = HMACSHA1Sign.VerifyStr(body, sign, out result);

                textBox_Result.Text = b ? result : String.Empty;

                MessageBox.Show(b ? "验证成功!" : "验证失败!", "温馨提示");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }
Ejemplo n.º 2
0
        public void TestDecryptor()
        {
            var    keyValue  = HMACSHA1Sign.CreatedSignKey();
            string signedStr = HMACSHA1Sign.SignStr(input, keyValue);

            String outStr = String.Empty;

            var b = HMACSHA1Sign.VerifyStr(signedStr, keyValue, out outStr);

            Assert.IsNotNull(signedStr);
            Assert.IsTrue(signedStr.Length > 0);
            Console.WriteLine(signedStr);

            Assert.IsTrue(b);
            Assert.IsNotNull(outStr);
            Console.WriteLine(outStr);
            Assert.IsTrue(outStr.Equals(input));
        }