C # MD5 Encrypted string

Source: Internet
Author: User

/// <summary>///encrypt strings with MD5, optionally generating 16-bit or 32-bit cryptographic strings/// </summary>/// <param name= "password" >string to encrypt</param>/// <param name= "bit" >number of digits, generally 16 or</param>/// <returns>returns the encrypted string</returns> Public stringMd5encrypt (stringPasswordintbit) {MD5CryptoServiceProvider Md5hasher=NewMD5CryptoServiceProvider ();byte[] hasheddatabytes;hasheddatabytes= Md5hasher.computehash (Encoding.GetEncoding ("gb2312"). GetBytes (password)); StringBuilder tmp=NewStringBuilder ();foreach(byteIinchhasheddatabytes) {tmp. Append (i.ToString ("X2"));}if(bit = = -)returnTmp. ToString (). Substring (8, -);Elseif(bit = = +)returnTmp. ToString ();//Default ConditionElse return string. Empty;}

/// <summary>///encrypt a string with MD5/// </summary>/// <param name= "password" >string to encrypt</param>/// <returns></returns> Public stringMd5encrypt (stringpassword) {MD5CryptoServiceProvider Md5hasher=NewMD5CryptoServiceProvider ();byte[] hasheddatabytes;hasheddatabytes= Md5hasher.computehash (Encoding.GetEncoding ("gb2312"). GetBytes (password)); StringBuilder tmp=NewStringBuilder ();foreach(byteIinchhasheddatabytes) {tmp. Append (i.ToString ("X2"));}returntmp. ToString ();}

Namespaces: System.Security.Cryptography.MD5CryptoServiceProvider

C # MD5 Encrypted string

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.