Example #1
0
        public void SignAndVerifyTest()
        {
            byte[] key     = SecretKeyAuth.GenerateKey();
            byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello, World!");

            byte[] signature    = SecretKeyAuth.Sign(message, key);
            bool   verification = SecretKeyAuth.Verify(message, signature, key);

            Assert.IsTrue(verification);
        }
        public void SecretKeyAuthSignAndVerifyTest()
        {
            byte[] key     = SecretKeyAuth.GenerateKey();
            String message = "Hello, World!";

            byte[] signature = SecretKeyAuth.Sign(System.Text.Encoding.UTF8.GetBytes(message), key);
            Assert.AreEqual(32, signature.Length);
            bool verification = SecretKeyAuth.Verify(System.Text.Encoding.UTF8.GetBytes(message), signature, key);

            Assert.IsTrue(verification);

            signature = SecretKeyAuth.Sign(message, key);
            Assert.AreEqual(32, signature.Length);
            verification = SecretKeyAuth.Verify(message, signature, key);
            Assert.IsTrue(verification);
        }
        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);
        }
Example #4
0
 public void TestGenerateKey()
 {
     Assert.AreEqual(32, SecretKeyAuth.GenerateKey().Length);
 }