/// <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