コード例 #1
0
        public static bool verify(string message, string signature, string key)
        {
            var encodedSignature = Encoding.UTF8.GetBytes(signature);
            var encodedKey       = Encoding.UTF8.GetBytes(key);

            return(SecretKeyAuth.VerifyHmacSha512(message, encodedSignature, encodedKey));
        }
コード例 #2
0
 public void SecretKeyAuthVerify512WithBadSignature()
 {
     SecretKeyAuth.VerifyHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                    Utilities.HexToBinary(
                                        "9f44681a662b7cde80c4eb34db5102b62a8b482272e3cceef73a334ec1d321c06a99b828e2ff921b4d1304bbd9480adfacf8c4c2ffbcbb4e5663446fda1235"),
                                    Encoding.UTF8.GetBytes("01234567890123456789012345678901"));
 }
コード例 #3
0
        public void SimpleVerifyHmacSha512Test()
        {
            var actual = SecretKeyAuth.VerifyHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                                        Utilities.HexToBinary("9f44681a662b7cde80c4eb34db5102b62a8b482272e3cceef73a334ec1d321c06a99b828e2ff921b4d1304bbd9480adfacf8c4c2ffbcbb4e5663446fda1235d2"),
                                                        Encoding.UTF8.GetBytes("01234567890123456789012345678901"));

            Assert.AreEqual(true, actual);
        }
コード例 #4
0
 public void SecretKeyAuthVerify512WithBadKey()
 {
     Assert.Throws <KeyOutOfRangeException>(() =>
     {
         SecretKeyAuth.VerifyHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                        Utilities.HexToBinary(
                                            "9f44681a662b7cde80c4eb34db5102b62a8b482272e3cceef73a334ec1d321c06a99b828e2ff921b4d1304bbd9480adfacf8c4c2ffbcbb4e5663446fda1235d2"),
                                        Encoding.UTF8.GetBytes("012345678901234567890123456789"));
     });
 }
コード例 #5
0
        public void HmacSha512Test()
        {
            var    key     = SecretKeyAuth.GenerateKey();
            string message = "Hello, World!";

            byte[] byteMessage = System.Text.Encoding.UTF8.GetBytes(message);
            var    sig1        = SecretKeyAuth.SignHmacSha512(message, key);
            var    sig2        = SecretKeyAuth.SignHmacSha512(byteMessage, key);

            // Verify the overload works
            Assert.AreEqual(Convert.ToBase64String(sig1), Convert.ToBase64String(sig2));

            var result = SecretKeyAuth.VerifyHmacSha512(message, sig1, key);

            Assert.IsTrue(result);
            result = SecretKeyAuth.VerifyHmacSha512(message, sig2, key);
            Assert.IsTrue(result);

            result = SecretKeyAuth.VerifyHmacSha512(byteMessage, sig1, key);
            Assert.IsTrue(result);
            result = SecretKeyAuth.VerifyHmacSha512(byteMessage, sig2, key);
            Assert.IsTrue(result);
        }