Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hash two blocks of data with HashAlgorithm in C#?

Tags:

c#

.net

hash

I need to hash a password with salt in C#. Salt is obtained from one source and is of type byte[], password is obtained from another source and is of type String.

Computing a hash of one block is quite easy - just call HashAlgorithm.ComputeHash() and it's done, but how do I compute a hash of two blocks without first building their concatenation?

like image 352
sharptooth Avatar asked Apr 28 '11 11:04

sharptooth


2 Answers

You'll want to look into the TransformBlock and TransformFinalBlock methods.

The latter MSDN link exemplifies use of both with a code sample that is potentially to much to post here.

like image 96
Grant Thomas Avatar answered Sep 28 '22 02:09

Grant Thomas


Use TransformBlock and TransformFinalBlock and then use the Hash property.

like image 22
Nick Avatar answered Sep 28 '22 04:09

Nick