private Boolean CompareHash(Type hashAlgorithmType, Byte[] plainText, Byte[] hashedBytes, Int32 saltLength = 16) { var hashAlgorithm = Activator.CreateInstance(hashAlgorithmType, true) as HashAlgorithm; if (hashAlgorithm == null) { throw new InvalidOperationException(String.Format("Could not create instance of type {0}.", hashAlgorithmType)); } var salt = CryptographyUtility.GetBytes(hashedBytes, saltLength); var targetHash = CryptographyUtility.CombineBytes(salt, hashAlgorithm.ComputeHash(CryptographyUtility.CombineBytes(salt, plainText))); return(CryptographyUtility.CompareBytes(hashedBytes, targetHash)); }
private Boolean CompareHash(Type keyedHashAlgorithmType, Byte[] symmetricKey, Byte[] plainText, Byte[] hashedText, Boolean saltEnabled = true, DataProtectionScope dataProtectionScope = DataProtectionScope.LocalMachine) { if (symmetricKey == null || plainText == null || hashedText == null) { return(false); } var keyedHashAlgorithm = Activator.CreateInstance(keyedHashAlgorithmType, true) as KeyedHashAlgorithm; if (keyedHashAlgorithm == null) { throw new InvalidOperationException(String.Format("Could not create instance of type {0}.", keyedHashAlgorithmType)); } keyedHashAlgorithm.Key = symmetricKey; var hashedPlainText = keyedHashAlgorithm.ComputeHash(plainText); // TODO: (DG) Support SALT! return(CryptographyUtility.CompareBytes(hashedPlainText, hashedText)); }