Implementation of MD5 encryption in asp.net--practical skills in VB

Source: Internet
Author: User
1. Methods in Web Projects
Copy Code code as follows:

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile ("AAAA", "MD5")
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile ("AAAA", "MD5")

To view document methods:
Copy Code code as follows:

Publicsharedfunctionhashpasswordforstoringinconfigfile (byvalpasswordasstring,byvalpasswordformatasstring) Asstring
Members belong to: System.Web.Security.FormsAuthentication
Summary:
Given a password and string that identifies the hash type, this routine produces a hash password that is appropriate for storing in the configuration file.
Parameters:
Password: the password to be hashed.
Passwordformat: The hash algorithm to use. Options have "SHA1" or "MD5".
return value:
Returns a string that contains a hash password.
Publicsharedfunctionhashpasswordforstoringinconfigfile (byvalpasswordasstring,byvalpasswordformatasstring) Asstring
Members belong to: System.Web.Security.FormsAuthentication
Summary:
Given a password and string that identifies the hash type, this routine produces a hash password that is appropriate for storing in the configuration file.
Parameters:
Password: the password to be hashed.
Passwordformat: The hash algorithm to use. Options have "SHA1" or "MD5".
return value:
Returns a string that contains a hash password.

2, VB application
Copy Code code as follows:

Publicsharedfunctionmd5str (byrefstrsourceasstring)
Dimdatatohashasbyte () = (NewSystem.Text.UnicodeEncoding). GetBytes (Strsource.tochararray)
Dimhashvalueasbyte () =ctype (Cryptography.CryptoConfig.CreateFromName ("MD5"), Cryptography.hashalgorithm). ComputeHash (Datatohash)
DimstrSBAsNewSystem.Text.StringBuilder
Foriasint16=0tohashvalue.length-1
Strsb.append (HashValue (i). ToString ("X2"))
Next
Dimcreatmd5=strsb.tostring
ReturncreatMD5
Endfunction
Publicsharedfunctionmd5str (byrefstrsourceasstring)
Dimdatatohashasbyte () = (NewSystem.Text.UnicodeEncoding). GetBytes (Strsource.tochararray)
Dimhashvalueasbyte () =ctype (Cryptography.CryptoConfig.CreateFromName ("MD5"), Cryptography.hashalgorithm). ComputeHash (Datatohash)
DimstrSBAsNewSystem.Text.StringBuilder
Foriasint16=0tohashvalue.length-1
Strsb.append (HashValue (i). ToString ("X2"))
Next
Dimcreatmd5=strsb.tostring
ReturncreatMD5
Endfunction

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.