Detailed introduction to C # Implementation of MD5 encryption and usage examples

Source: Internet
Author: User
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 ();} 
Related Article

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.