比较 2 个哈希字节数组

Comparing 2 hashed byte arrays

考虑以下代码:

    MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
    byte[] hashedBytes;
    byte[] previousHashedBytes;

    UTF8Encoding encoder = new UTF8Encoding();
    // New hashedBytes array
    hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(someString + theValue));
    // previousHashedBytes retrieved from DB
    previousHashedBytes = GetPreviousValueFromDB();

然后应用程序将 hashedBytes 插入到数据库中。由于新政策,我需要确保 无法重复使用 hashedBytes 值,因此我需要一些方法来将现有的 hashedBytes 值与新值进行比较。

注意someString的值始终相同。

如何比较 previousHashedByteshashedBytes 是否相同?

基本上,如果您只有数据库中的字节散列,您想比较两个字节数组?

你可以在这里得到这个:Comparing two byte arrays in .NET

可能适合您的选项之一是:

StructuralComparisons.StructuralEqualityComparer.Equals(hashedBytes,
 previousHashedBytes)