C # MD5 value calculation

Source: Internet
Author: User

C # Compute MD5
       /// <summary>        ///MD5 Calculation/// </summary>        /// <param name= "str" >string to be computed for MD5</param>        /// <returns>a 32-bit string</returns>         Public Static stringGETMD5 (stringstr) {            varMD5 = MD5. Create ();//or var md5 = new MD5CryptoServiceProvider ();            varBytvalue =Encoding.UTF8.GetBytes (str); varBythash =Md5.computehash (Bytvalue); varSB =NewStringBuilder (); foreach(varBinchBythash) {sb. Append (B.tostring ("X2")); }            returnsb.        ToString (); }

Ps:tostring ("X2") explanation

The uppercase x:tostring ("X2") is converted to uppercase 16 binary.

The lowercase x:tostring ("X2") is converted to lowercase 16 binary.

2 indicates the output two bits, the insufficient 2 bits of the front complement 0, such as 0x0A if not 2, will only output 0xA

C # MD5 value calculation

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.