public void HashMD5() { byte[] plaintext = new byte[] {0, 1, 2, 3}; HashCryptographer cryptographer = new HashCryptographer(typeof(MD5CryptoServiceProvider).AssemblyQualifiedName); byte[] hash1 = cryptographer.ComputeHash(plaintext); Assert.IsFalse(CryptographyUtility.CompareBytes(plaintext, hash1)); MD5 md5 = MD5CryptoServiceProvider.Create(); byte[] hash2 = md5.ComputeHash(plaintext); Assert.IsTrue(CryptographyUtility.CompareBytes(hash1, hash2)); }
public void HashHMACSHA1() { byte[] plaintext = new byte[] { 0, 1, 2, 3 }; HashCryptographer cryptographer = new HashCryptographer(typeof(HMACSHA1), key); byte[] hash1 = cryptographer.ComputeHash(plaintext); Assert.IsFalse(CryptographyUtility.CompareBytes(plaintext, hash1)); KeyedHashAlgorithm hmacsha1 = HMAC.Create(); hmacsha1.Key = key.DecryptedKey; byte[] hash2 = hmacsha1.ComputeHash(plaintext); Assert.IsTrue(CryptographyUtility.CompareBytes(hash1, hash2)); }
public void HashMD5() { byte[] plaintext = new byte[] { 0, 1, 2, 3 }; HashCryptographer cryptographer = new HashCryptographer(typeof(MD5CryptoServiceProvider)); byte[] hash1 = cryptographer.ComputeHash(plaintext); Assert.IsFalse(CryptographyUtility.CompareBytes(plaintext, hash1)); MD5 md5 = MD5CryptoServiceProvider.Create(); byte[] hash2 = md5.ComputeHash(plaintext); Assert.IsTrue(CryptographyUtility.CompareBytes(hash1, hash2)); }
public void HashHMACSHA1() { byte[] plaintext = new byte[] { 0, 1, 2, 3 }; HashCryptographer cryptographer = new HashCryptographer(typeof(HMACSHA1), key); byte[] hash1 = cryptographer.ComputeHash(plaintext); Assert.IsFalse(CryptographyUtility.CompareBytes(plaintext, hash1)); KeyedHashAlgorithm hmacsha1 = HMACSHA1.Create(); hmacsha1.Key = key.DecryptedKey; byte[] hash2 = hmacsha1.ComputeHash(plaintext); Assert.IsTrue(CryptographyUtility.CompareBytes(hash1, hash2)); }