C# SHA-1 vs. PHP SHA-1...Different Results?

Posted by Arcdigital on Stack Overflow See other posts from Stack Overflow or by Arcdigital
Published on 2009-04-26T04:23:41Z Indexed on 2010/05/18 12:40 UTC
Read the original article Hit count: 312

Filed under:
|
|
|
|

Hey, I am trying to calculate a SHA-1 Hash from a string, but when I calculate the string using php's sha1 function I get something different than when I try it in C#. I need C# to calculate the same string as PHP (since the string from php is calculated by a 3rd party that I cannot modify). How can I get C# to generate the same hash as PHP? Thanks!!!

String = [email protected]

C# Code (Generates d32954053ee93985f5c3ca2583145668bb7ade86)

        string encode = secretkey + email;
		UnicodeEncoding UE = new UnicodeEncoding();
		byte[] HashValue, MessageBytes = UE.GetBytes(encode);
		SHA1Managed SHhash = new SHA1Managed();
		string strHex = "";

		HashValue = SHhash.ComputeHash(MessageBytes);
		foreach(byte b in HashValue) {
			strHex += String.Format("{0:x2}", b);
		}

PHP Code (Generates a9410edeaf75222d7b576c1b23ca0a9af0dffa98)

sha1();

© Stack Overflow or respective owner

Related posts about c#

Related posts about php