0

What is the best way to compare two byte arrays in C#? I do not wish to use a for loop.

I have the following arrays:

byte[] hashBytes = Convert.FromBase64String(pass);

and:

byte[] hash = pbkdf2.GetBytes(20);

I have tried using:

bool isEqual = Enumerable.SequenceEqual(hashBytes, hash);

However, it always returns false.

3
  • 2
    Are you sure they are indeed equal in the case where SequenceEqual didn't work? Commented Dec 9, 2015 at 17:39
  • 1
    " I do not wish to use a for loop." - Why not? Commented Dec 9, 2015 at 17:41
  • I'd recommend a constant time comparison, but of course it still uses a loop. Commented Dec 9, 2015 at 23:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.