Knowledge about sha1 and MD5 Encryption

Source: Internet
Author: User

MD5-related classes:

System. Security. cryptography. MD5
System. Security. cryptography. md5cryptoserviceprovider ()
System. Web. Security. formsauthentication. hashpasswordforstoringinconfigfile (strsource, "MD5 ")

Sha1 related classes:

System. Security. cryptography. sha1
System. Security. cryptography. sha1cryptoserviceprovider ()
System. Web. Security. formsauthentication. hashpasswordforstoringinconfigfile (strsource, "sha1 ")

 

Obtain the sha1-encrypted string
Public String encrypttosha1 (string Str)
{
Sha1cryptoserviceprovider sha1 = new sha1cryptoserviceprovider ();
Byte [] str1 = encoding. utf8.getbytes (STR );
Byte [] str2 = sha1.computehash (str1 );
Sha1.clear ();
(Sha1 as idisposable). Dispose ();
Return convert. tobase64string (str2 );
}

Bytes ---------------------------------------------------------------------------------------------------------

Obtain the MD5-encrypted string
Public String encrypttomd5 (string Str)
{
Md5cryptoserviceprovider MD5 = new md5cryptoserviceprovider ();
Byte [] str1 = encoding. utf8.getbytes (STR );
Byte [] str2 = md5.computehash (str1, 0, str1.length );
Md5.clear ();
(MD5 as idisposable). Dispose ();
Return convert. tobase64string (str2 );
}

-----------------------------------------------------------------------

 

These encryption functions are executed on the server. That is to say, when the user enters the password and transfers the data from the client to the server, the user's password is not protected, which is very dangerous. The banking practice is to install ActiveX controls on the client, encrypt some important information on the client, and then send.

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.