C#MD5 Calculation Code

Source: Internet
Author: User
Tags md5 hash

/// <summary>///calculates a MD5 hash from the given string and uses the given///encoding./// </summary>/// <param name= "Input" >Input String</param>/// <param name= "useencoding" >Encoding Method</param>/// <returns>MD5 Computed String</returns> Public Static stringCalculateMD5 (stringInput, Encoding useencoding)    {System.Security.Cryptography.MD5CryptoServiceProvider cryptoservice; Cryptoservice=NewSystem.Security.Cryptography.MD5CryptoServiceProvider (); byte[] Inputbytes =useencoding.getbytes (Input); Inputbytes=Cryptoservice.computehash (inputbytes); returnBitconverter.tostring (inputbytes). Replace ("-","");}/// <summary>///calculates a MD5 hash from the given string.///(by using the default encoding)/// </summary>/// <param name= "Input" >Input String</param>/// <returns>MD5 Computed String</returns> Public Static stringCalculateMD5 (stringInput) {    //That's just a shortcut to the base method    returnCalculateMD5 (Input, System.Text.Encoding.Default);}//Invocation Example://The example below shows how to verify a password//by using a md5-hash://Password could is from user inputstringPlainpassword ="Secret Password";stringHashedpassword =CalculateMD5 (Plainpassword);//This hash could come from the databasestringStoredpassword ="a584efafa8f9ea7fe5cf18442f32b07b";//is the hashes equal?if(Hashedpassword = =Storedpassword) MessageBox.Show ("Correct password!");ElseMessageBox.Show ("Sorry, bad password:-(");

C#MD5 Calculation Code

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.