. Net, including Asp.net and VB.net.

Source: Internet
Author: User

 

I. Asp.net method:

Need to introduce

Imports Microsoft. VisualBasic
Imports system. Management

Function getmd5 (byval STR as string, byval code as int16) as string <br/> If code = 16 then <br/> return system. web. security. formsauthentication. hashpasswordforstoringinconfigfile (STR, "MD5 "). substring (8, 16) </P> <p> else '32-bit encryption <br/> return system. web. security. formsauthentication. hashpasswordforstoringinconfigfile (STR, "MD5") <br/> end if <br/> 'specify the encoding utf8, utf7, and Unicode. '<br/>' system is used. text. encoding. utf8.getbytes (strsource) </P> <p> end Function

Ii. VB.net

Need to introduce

Imports system. Management
Imports system. Security. Cryptography
Imports system. Text

Function getmd5 (byval mystr as string) as string </P> <p> 'create a new instance of the MD5 object. <br/> dim md5hasher as MD5 = md5.create () </P> <p> 'convert the input string to a byte array and compute the hash. <br/> 'dim data as byte () = md5hasher. computehash (encoding. default. getbytes (mystr) <br/> dim data as byte () = md5hasher. computehash (encoding. utf8.getbytes (mystr) <br/> 'note that the encoding method is changed to the UTF-8 to be consistent with the Asp.net encoding method, otherwise the same encryption source string, inconsistent results </P> <p> 'create a new stringbuilder to collect the bytes <br/> 'and create a string. <br/> dim sbuilder as new stringbuilder () </P> <p> 'loop through each byte of the hashed data <br/> 'and format each one as a hexadecimal string. <br/> dim I as integer <br/> for I = 0 to Data. length-1 <br/> sbuilder. append (data (I ). tostring ("X2") <br/> next I </P> <p> 'Return The hexadecimal string. <br/> return sbuilder. tostring () </P> <p> end Function

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.