This article mainly introduces the MD5 encryption function and usage of C # implementation, and analyzes the definition and use method of C # MD5 encryption class with the example form, the friend who needs can refer to the following
This paper describes the MD5 encryption function and usage of C # implementation. Share to everyone for your reference, as follows:
1. Create MD5Str.cs Encryption Processing class
public class md5str{//<summary>// string MD5 encryption//</summary>// <param name= "Text" > String to encrypt </param> //<returns> redaction </returns> public static string MD5 (String Text) { byte[] buffer = System.Text.Encoding.Default.GetBytes (Text); Try { System.Security.Cryptography.MD5CryptoServiceProvider check; Check = new System.Security.Cryptography.MD5CryptoServiceProvider (); byte[] Somme = check.computehash (buffer); string ret = ""; foreach (Byte A in Somme) { if (a <) ret + = "0" + a.tostring ("X"); else ret + = a.tostring ("X"); } return ret. ToLower (); } Catch { throw;}} }
2. Run the test
static void Main (string[] args) {String data = "123456789";//data to be encrypted string encodestr = ""; Encrypted text ENCODESTR = MD5STR.MD5 (data); Console.WriteLine ("Original text: {0}", data); Console.WriteLine ("Encrypted text: {0}", ENCODESTR); Console.read ();}