C # implementation MD5 encryption

Source: Internet
Author: User
Tags hash md5 md5 encryption md5 hash

1. First create a MD5 hash algorithm.

((HashAlgorithm) System.Security.Cryptogrophy.CryptoConfig.CreateFromName ("MD5")). ComputeHash (System.Text.UTF8.GetBytes (input))

2. Calculate the hash value

Use method: ComputeHash (byte[] value);

3. Convert to String.

1protected virtual string HashMD5(string input)
2    {
3      byte[] result = ((HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(System.Text.Encoding.UTF8.GetBytes(input));
4      StringBuilder output = new StringBuilder(16);
5
6      for (int i = 0; i < result.Length; i++)
7      {
8        // convert from hexa-decimal to character
9        output.Append((result[i]).ToString( "x2", System.Globalization.CultureInfo.InvariantCulture));
10      }
11      return output.ToString();
12    }
13

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.