public void MD5TestString() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] hashBytes = f.Hash(HashAlgorithmName.MD5, "Hello world"); string result = System.Convert.ToBase64String(hashBytes); // Assert Assert.AreEqual("PiWWCnnbxptnTNTsZ6csYg==", result); }
public void SHA512TestBytes() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes("Hello world"); byte[] hashBytes = f.Hash(HashAlgorithmName.SHA512, inputBytes); string result = System.Convert.ToBase64String(hashBytes); // Assert Assert.AreEqual("t/eDuu2Cl/DbkXRiGE/08I5pwtXl95qUJgD5cl9Yzh8pwYE5v4CwbA//K900c4RS7PQMSIwip+PYDN9vnBwNRw==", result); }
public void SHA256TestBytes() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes("Hello world"); byte[] hashBytes = f.Hash(inputBytes); string result = System.Convert.ToBase64String(hashBytes); // Assert Assert.AreEqual("ZOyIygCyaOW6GjVnihtTFtIS9PNmskdyMlNKiuyjfzw=", result); }
public void SHA256TestString() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] hashBytes = f.Hash("Hello world"); string result = System.Convert.ToBase64String(hashBytes); //System.Console.WriteLine(base64Result); // Assert Assert.AreEqual("ZOyIygCyaOW6GjVnihtTFtIS9PNmskdyMlNKiuyjfzw=", result); }
public void HMACSHA512TestBytesWithKey() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] inputDataBytes = System.Text.Encoding.UTF8.GetBytes("Hello world"); byte[] keyBytes = Convert.FromBase64String("otkYmuRbaC/sRM7NHTXkN+6ntZTRosrF7t1bQNYQjCM5tor4I9qZMUXOQXZP/+bE/Wjw7t4xAKhEw73SWjqeVVFLfOwpB1ssqWRWDJbGed0mu49XK3Gd/E/luZnmF0KvE/NP103Frdqt9oH2GM1SqvNIIZLm20IytkOEEqX/660="); byte[] hashBytes = f.Hash(KeyedHashAlgorithmName.HMACSHA512, inputDataBytes, keyBytes); //string keyBase64 = Convert.ToBase64String(keyBytes); string resultBase64 = Convert.ToBase64String(hashBytes); Console.WriteLine("Result = [{0}]", resultBase64); // Assert Assert.AreEqual("Ywri+XnoJCV75fBvHEGkMa0OJR8ZoiphQJygP8T7e9r8nLmVVFNkt0ppD+OcMaEDeAiiktCfj2ixRNQByScr6w==", resultBase64); }
public void HMACSHA256TestStringWithKey() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] keyBytes = Convert.FromBase64String("1VjUDZCtOU+sKnGTziG3E4HTlkPOdBMkjtWM1wkQaiA6qS3NkYLAS6swIDTPJYRjZfH0hi2MBWYMU/m+uw3evA=="); byte[] hashBytes = f.Hash("Hello world", keyBytes); string keyBase64 = Convert.ToBase64String(keyBytes); string resultBase64 = Convert.ToBase64String(hashBytes); Console.WriteLine("Key = [{0}]", keyBase64); Console.WriteLine("Result = [{0}]", resultBase64); // Assert Assert.AreEqual("gJN9jxH8dPy4x9gezzE+OqkdyLIqMShC9tkw8oKqXcc=", resultBase64); }
public void HMACSHA256TestStringNoKey() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] keyBytes; byte[] hashBytes = f.Hash("Hello world", out keyBytes); string keyBase64 = Convert.ToBase64String(keyBytes); string resultBase64 = Convert.ToBase64String(hashBytes); Console.WriteLine("Key = [{0}]", keyBase64); Console.WriteLine("Result = [{0}]", resultBase64); // Assert Assert.NotNull(keyBase64); Assert.NotNull(resultBase64); }
public void HMACSHA256TestBytesNoKey() { // Arrange CryptographyFactory f = new CryptographyFactory(); // Act byte[] inputDataBytes = System.Text.Encoding.UTF8.GetBytes("Hello world"); byte[] keyBytes; byte[] hashBytes = f.Hash(inputDataBytes, out keyBytes); string keyBase64 = Convert.ToBase64String(keyBytes); string resultBase64 = Convert.ToBase64String(hashBytes); Console.WriteLine("Key = [{0}]", keyBase64); Console.WriteLine("Result = [{0}]", resultBase64); // Assert Assert.NotNull(keyBase64); Assert.NotNull(resultBase64); }