If .net sha1 hash expects a byte array, and php sha1() wants a string, can I match the results?
Posted
by lynn
on Stack Overflow
See other posts from Stack Overflow
or by lynn
Published on 2009-03-05T18:51:17Z
Indexed on
2010/06/14
7:12 UTC
Read the original article
Hit count: 252
I have a set of bytes I want to apply an sha1 hash to. One hash will be in .net, the other in PHP. Then I'll test to see if they match.
In .net, you can create a byte array and use sha.ComputeHash().
byte[] data = new byte[DATA_SIZE];
byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
// This is one implementation of the abstract class SHA1.
result = sha.ComputeHash(data);
In PHP, you call sha1($string).
I can't do anything about the .net side of the code, but how can I get the same hash out of PHP that .net will generate?
Please note: I am ONLY able to work on the PHP side of this. The .net stuff is fixed and can't be modified. Thanks!
© Stack Overflow or respective owner