Excerpt from Baidu:
byte conversion to a string to be guaranteed to be 2-bit width ah, a byte of 0 converted to a string must be 00, otherwise you will lose the number of bits ah. Not only is 0,1~9 also the same.
The code is as follows:
/// <summary> ///MD5 Encryption Helper class/// </summary> Public classMd5helper {#regionMD5 Conversion/// <summary> ///computes the MD5 hash value of the specified string/// </summary> /// <param name= "message" >the string to be hashed</param> /// <returns></returns> Public Static stringConvertMD5 (stringmessage) { if(string. IsNullOrEmpty (message)) {return string. Empty; } Else{MD5 MD5=MD5. Create (); byte[] Source =Encoding.UTF8.GetBytes (message); byte[] result =Md5.computehash (source); StringBuilder Buffer=NewStringBuilder (result. Length); for(inti =0; I < result. Length; i++) {buffer. Append (Result[i]. ToString ("X2"));//converts a byte value to a hexadecimal string } returnbuffer. ToString (); } } #endregion }
Getting Started with C # programming--MD5 encryption