About the MD5 encryption function in Asp,asp.net,vb.net

Source: Internet
Author: User
Tags md5 md5 encryption
asp.net| function | Encryption in ASP, we used such as the Dynamic Network forum, such as the ASP MD5 function encrypted string is such as:
1165d25d8cd021d5

And in ASP.net, the following method: code


System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (password. Text, "MD5")

The results of MD5 encryption are:
12c403b91165d25d8cd021d5f9b5bb7f

The reason is because, in the ASP, the MD5 function is to use the 9th to 25th digit in the 32-bit MD5 HashValue to write for ciphertext. Knowing this, the asp.net results can be used to compare the password strings in the old database.

No. 353, 354 lines in the ASP's MD5 function: code


' MD5 = LCase (Wordtohex (a) & Wordtohex (b) & Wordtohex (c) & Wordtohex (d)) Md5=lcase (Wordtohex (b) & Wordtohe X (c)) ' I crop this to fit 16byte database password:D

The first sentence is to take all 32-digit ciphertext, the second sentence is to take the middle 9th to 25th Digit is 16-bit cipher text.

To the vb.net problem again, in vb.net, can not use the System.Web.Security namespace, can not use the above simple method for MD5 encryption. I write the following function to handle:

VB.net: Code


' MD5 cryptographic functions public Shared function MD5 (ByVal strsource As String, ByVal Code as Int16) As String ' here is the original ASCII encoded cipher, if you want to use Han Word to do the password, you can use UnicodeEncoding, but will be incompatible with the MD5 function in ASP Dim Datatohash as Byte () = (New System.Text.ASCIIEncoding). GetBytes (strsource) Dim HashValue as Byte () = CType (System.Security.Cryptography.CryptoConfig.CreateFromName (" MD5 "), System.Security.Cryptography.HashAlgorithm). ComputeHash (datatohash) Dim i as Integer Select Case Code case ' select 16-bit encryption result for i = 4 to one M D5 + = Hex (HashValue (i)). ToLower Next Case ' Select the 32-bit encryption result for i = 0 to MD5 + = Hex (HashValue (i)). ToLower Next case Else ' code error, returns all strings, that is, 32-bit character for i = 0 to HashValue. Length-1 MD5 + = Hex (HashValue (i)). ToLower Next End Select End Function







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.