The application of C # Encryption in practice _c# tutorial

Source: Internet
Author: User
In the system administrator has a practical application, for a database management system, database security is very important, so the password stored to the database is usually encrypted. Even with the hack database, it will not be easy to steal your account and password, which can reduce your unnecessary losses. OK, here are some basic implementation codes:
The encrypted code format is the same:
First step:
Copy Code code as follows:

<span style= "FONT-SIZE:16PX; Color: #000000; >system.web.security.formsauthentication.hashpasswordforstoringinconfigfile (str, target) </span>

Targe incoming is the way of encryption, SHA1 and MD5 are common ways. <br> below give a concrete example:<br> the first step: write the following code in the background of the Web page:
Copy Code code as follows:

<span style= "FONT-SIZE:16PX; Color: #000000; > String str = this.tbPwd.Text;
String str1 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (str, "SHA1");
String str2 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (str, "MD5");
This.lbName.Text = "SHA1 encrypted password:" + str1 + "<br/> SHA1 encryption length is:" + str1. Length + "<br/><br/>" + "MD5 encrypted password:" + str2 + "<BR/>MD5 encryption lengths are:" + str2. Length;
</span>

Part II: Refreshes the Web page as shown in the following illustration:

An empty string is encrypted even if it is empty and nothing is entered
Third Step: Enter a string: 123456, the result of clicking the button is as follows:

As can be seen from the above, SHA1 and MD5 have a great effect on the protection of data in concrete actual projects.

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.