1

Consider the following code:

    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();

The application then inserts hashedBytes into a database. I need to make sure due to a new policy that hashedBytes value cannot be reused, so I need some way to compare an existing hashedBytes value with a new one.

Note: the value for someString is always the same.

How does one compare previousHashedBytes with hashedBytes to see if they are the same?

1

1 Answer 1

3

Basically, if you only have the byte hash in DB, you want to compare two byte array ?

You can get this here: Comparing two byte arrays in .NET

One of the options that might work for you is:

StructuralComparisons.StructuralEqualityComparer.Equals(hashedBytes,
 previousHashedBytes)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.