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