Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the encryption method of ASP.NET MD5 and SHA1

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail about ASP.NET MD5 and SHA1 encryption method is what, the article content quality is high, so Xiaobian share for everyone to make a reference, I hope you read this article after the relevant knowledge has a certain understanding.

ASP.NET MD5 and SHA1 encryption methods what? Let's see what MD5 is. MD5 stands for Message-Digest Algorithm 5, which was developed by Ronald l. Rivest was developed and developed through MD2, MD3 and MD4. Its purpose is to allow large amounts of information to be "compressed" into a secure format (i.e., a string of bytes of arbitrary length transformed into a large integer of a certain length) before signing it with a private key using digital signature software. Whether md2, md4, or md5, they all need to take a random length message and produce a 128-bit digest.

Cryptographic hash functions map binary strings of arbitrary length to small binary strings of fixed length. Cryptographic hash functions have the property that it is computationally unlikely to find two different inputs hashed to the same value; that is, the hash values of two sets of data match only if the corresponding data also matches. Small changes to the data can produce unpredictable large changes in the hash value. So it's hard to pick up anything from encrypted text.

What is SHA1 in ASP.NET SHA1 encryption? SHA1 stands for Secure Hash Algorithm.

The MD5 algorithm has a hash size of 128 bits. The SHA1 hash size is 160 bits. Both algorithms are irreversible.

On August 17, 2004, at Crypto'2004 in Santa Barbara, California, Professor Wang Xiaoyun from Shandong University of China gave a report on decoding MD5, HAVAL-128, MD4 and RIPEMD algorithms, and announced the cracking results of MD series algorithms. The bastion of MD5, which declared the world password standard impenetrable, collapsed suddenly, causing an uproar in the cryptography community. But I think for us to do ordinary software, this encryption security level is enough to use.

ASP.NET MD5 and SHA1 encryption methods have been introduced, now let's see what specific classes there are?

We usually use nothing more than encrypted user passwords, encrypted passwords stored in the database, password comparison, the user input password and then encrypted, and then compared with the database ciphertext. As for ASP.NET class is how to implement encryption algorithm, we do not need to care about this, will use the line.

Here are a few encryption methods in Asp.net. There are two encryption algorithms, namely MD5 and SHA1 mentioned above. The example I give here is MD5 as an example. SHA1 is roughly the same, but the classes used are different.

MD5 related classes for ASP.NET MD5 and SHA1 encryption:

System.Security.Cryptography.MD5

System.Security.Cryptography.MD5CryptoServiceProvider()

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "MD5")

ASP.NET MD5 and SHA1 encryption SHA1 related classes:

System.Security.Cryptography.SHA1

System.Security.Cryptography.SHA1CryptoServiceProvider()

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "SHA1")

The method is as follows: (vs2005)

/** //// ///Method 1: Create objects by using the new operator /// ///plaintext to be encrypted ///Returns the 16-bit encryption result, which takes bits 9 to 25 of the 32-bit encryption result public string Get_MD5_Method1(string strSource) { //new System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); //Get ciphertext byte array byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource)); //Convert to string and take 9 to 25 bits string strResult = BitConverter.ToString(bytResult, 4, 8); //Convert to string, 32 bits //string strResult = BitConverter.ToString(bytResult); //BitConverter produces a delimiter in the middle of each character, which needs to be removed strResult = strResult.Replace("-", ""); return strResult; } /** //// ///Method 2: Create an object that implements a particular encryption algorithm by calling the Create method on the abstract class of the particular encryption algorithm. /// ///plaintext to be encrypted ///Return 32-bit encryption results public string Get_MD5_Method2(string strSource) { string strResult = ""; //Create System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); //Note the choice of encoding UTF8, UTF7, Unicode, etc. byte[] bytResult = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strSource)); //Convert arrays of byte type to strings for (int i = 0; i < bytResult.Length; i++) { //hexadecimal conversion strResult = strResult + bytResult[i].ToString("X"); } return strResult; } /** //// ///Method 3: Generate directly using HashPasswordForStoringInConfigFile /// ///plaintext to be encrypted ///Return 32-bit encryption results public string Get_MD5_Method3(string strSource) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "MD5"); }

These encryption functions are executed on the server side, that is to say, when the user enters the password and transmits it from the client to the server, the user's password is not protected and is very dangerous. The bank's practice is to install ActiveX controls on the client side, and encrypt some important information on the client side before sending it. This even will not pull, I hope to learn to do this ActiveX control.

ASP.NET MD5 and SHA1 encryption is introduced here.

About ASP.NET MD5 and SHA1 encryption method is what to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report