SHA1 encryption, C # and PHP encryption results are not the same

Source: Internet
Author: User
Tags sha1 sha1 encryption

Today in docking other people's system, found a very pit problem, SHA1 encryption problem

Others system SHA1 encryption is written in PHP, we are C #.

The same is true for string 123456 encryption, C # 's SHA1 encrypted string is feqncco3yq9h5zugld3czjt4lbs=
The encrypted character of PHP is 7c4a8d09ca3762af61e59520943dc26494f8941b

To solve such a problem, recommend:

<summary>
SHA1 encryption, as with PHP encryption results
</summary>
<param name= "Data" ></param>
<returns></returns>
public static string Sha1sign (String data)
{
byte[] Temp1 = Encoding.UTF8.GetBytes (data);
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider ();
byte[] Temp2 = Sha.computehash (TEMP1);
Sha.            Clear (); Look, you can't use this.
String output = Convert.tobase64string (TEMP2);//cannot be converted directly to base64string
var output = bitconverter.tostring (TEMP2);
Output = output. Replace ("-", "");
Output = output. ToLower ();
return output;
}

That's the same result.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.