可以将AES用作哈希算法的一部分。输入数据是否用作键。下面是一个可能的示例。这行得通吗,并且安全吗?
static byte[] AesOneWayEncrypt(byte[] input)
{
using (Aes aes = Aes.Create())
{
aes.Key = keccak.ComputeBytes(input).GetBytes();
Array.Copy(keccak.ComputeBytes(aes.Key).GetBytes(), aes.IV, 16);
ICryptoTransform encryptor = aes.CreateEncryptor();
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
{
cs.Write(data);
}
encryptedData.AddRange(ms.ToArray());
}
}
}
答案 0 :(得分:1)
有可能,但这是性能和安全性的折衷。好的散列函数的要求与好的加密算法的要求不同。例如,在这里阅读:https://en.wikipedia.org/wiki/Cryptographic_hash_function#Hash_functions_based_on_block_ciphers