C # Md5Hash,

Source: Internet
Author: User

C # Md5Hash,

/// <Summary> /// MD5 32-bit encryption (uppercase) /// </summary> /// <param name = "str"> </param> /// <returns> </returns> static string UserMd5 (string str) {string cl = str; string pwd = ""; MD5 md5 = MD5.Create (); // instantiate an md5 object. // The encrypted MD5 object is a byte array, here, you need to pay attention to Encoding UTF8/Unicode and so on. Select byte [] s = md5.ComputeHash (Encoding. UTF8.GetBytes (cl); // converts an array of the byte type to a string using a loop. This string is formatted by regular characters for (int I = 0; I <s. length; I ++) {// use the hexadecimal format of the obtained string.. The characters in the format are lowercase letters. If uppercase letters (X) are used, the characters in the format are uppercase letters pwd = pwd + s [I]. toString ("X");} return pwd ;} /// <summary> /// after MD5 16-bit encryption, the password is in lowercase /// </summary> /// <param name = "ConvertString"> </param> /// <returns> </returns> public static string GetMd5str (string ConvertString) {MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider (); string t2 = BitConverter. toString (md5.ComputeHash (UTF8Encoding. default. getBytes (ConvertString), 4, 8); t2 = t2.Replace ("-", ""); t2 = t2.ToLower (); return t2 ;} /// <summary> /// after MD5 16-bit encryption, the password is capitalized /// </summary> /// <param name = "ConvertString"> </param> /// <returns> </returns> public static string GetMd5Str (string ConvertString) {MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider (); string t2 = BitConverter. toString (md5.ComputeHash (UTF8Encoding. default. getBytes (ConvertString), 4, 8); t2 = t2.Replace ("-", ""); return t2 ;} /// <summary> /// MD5 encryption (lower case) /// </summary> /// <param name = "input"> </param> /// <returns> </returns> private static string Md5Hash (string input) {MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider (); byte [] data = md5Hasher. computeHash (Encoding. default. getBytes (input); StringBuilder sBuilder = new StringBuilder (); for (int I = 0; I <data. length; I ++) {sBuilder. append (data [I]. toString ("x2");} return sBuilder. toString ();}

  

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.