private static byte[] HashEncrypt(HashCryptoType format, byte[] input, byte[] salt) { byte[] inArray = null; var hashAlgorithm = HashAlgorithm.Create(format.ToString()); if (hashAlgorithm is KeyedHashAlgorithm) { var algorithm = (KeyedHashAlgorithm)hashAlgorithm; if (salt != null && salt.Length > 0) { algorithm.Key = salt; } inArray = algorithm.ComputeHash(input); } else { byte[] buffer; if (salt != null && salt.Length > 0) { buffer = new byte[input.Length + salt.Length]; Buffer.BlockCopy(input, 0, buffer, 0, input.Length); Buffer.BlockCopy(salt, 0, buffer, input.Length, salt.Length); } else { buffer = input; } inArray = hashAlgorithm.ComputeHash(buffer); } return(inArray); }
private static byte[] HashEncrypt(HashCryptoType format, byte[] input, byte[] salt) { byte[] buffer2; HashAlgorithm algorithm = HashAlgorithm.Create(format.ToString()); if (algorithm is KeyedHashAlgorithm) { KeyedHashAlgorithm algorithm2 = (KeyedHashAlgorithm)algorithm; if ((salt != null) && (salt.Length > 0)) { algorithm2.Key = salt; } return(algorithm2.ComputeHash(input)); } if ((salt != null) && (salt.Length > 0)) { buffer2 = new byte[input.Length + salt.Length]; Buffer.BlockCopy(input, 0, buffer2, 0, input.Length); Buffer.BlockCopy(salt, 0, buffer2, input.Length, salt.Length); } else { buffer2 = input; } return(algorithm.ComputeHash(buffer2)); }