예제 #1
0
        public static string sign(string privateKey, string cipherText)
        {
            var encodedKey = Encoding.UTF8.GetBytes(privateKey);

            byte[] signature = SecretKeyAuth.SignHmacSha512(cipherText, encodedKey);
            return(Encoding.UTF8.GetString(signature));
        }
 public void SecretKeyAuthSign512WithBadKey()
 {
     Assert.Throws <KeyOutOfRangeException>(() =>
     {
         SecretKeyAuth.SignHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                      Encoding.UTF8.GetBytes("012345678901234567890123456789"));
     });
 }
예제 #3
0
        public void SimpleAuthHmacSha512Test()
        {
            var expected = Utilities.HexToBinary("9f44681a662b7cde80c4eb34db5102b62a8b482272e3cceef73a334ec1d321c06a99b828e2ff921b4d1304bbd9480adfacf8c4c2ffbcbb4e5663446fda1235d2");
            var actual   = SecretKeyAuth.SignHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                                        Encoding.UTF8.GetBytes("01234567890123456789012345678901"));

            CollectionAssert.AreEqual(expected, actual);
        }
        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);
        }
 public void SecretKeyAuthSign512WithBadKey()
 {
     SecretKeyAuth.SignHmacSha512(Encoding.UTF8.GetBytes("Adam Caudill"),
                                  Encoding.UTF8.GetBytes("012345678901234567890123456789"));
 }