The usage and examples of C # Md5hash

Source: Internet
Author: User
Tags md5 encryption
<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 a MD5 pair like//After encryption is an array of byte type, here to note the choice of encoding utf8/unicode, etc. byte[] s = MD5.            ComputeHash (Encoding.UTF8.GetBytes (CL)); By using loops, an array of byte types is converted to a string that is a regular character formatted for (int i = 0; i < s.length; i++) {//Will be To the string using the hexadecimal type format. The formatted character is a lowercase letter, and if uppercase (X) is used, the character after the format is uppercase characters pwd = pwd + s[i].            ToString ("X");        } return pwd; }///<summary>//MD5 16-bit encryption after the password is lowercase//</summary>//<param name= "converts Tring "></param>///<returns></returns> public static string Getmd5str (String convertst Ring) {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>//MD5 16-bit encryption password is uppercase///</summary>//<param name= "converts Tring "></param>///<returns></returns> public static string Getmd5str (String convertst            Ring) {MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider ();            String t2 = bitconverter.tostring (Md5.computehash (UTF8Encoding.Default.GetBytes (convertstring)), 4, 8); t2 = T2.            Replace ("-", "" ");        return T2; }///<summary>//MD5 encryption (lowercase)///</summary>//<param name= "input" ></pa     ram>//<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.