[My asp.net learning process] Invoke a simple encryption method of a class library library

Source: Internet
Author: User
Tags empty md5 md5 encryption sha1 sha1 encryption
asp.net| encryption asp.net with a MD5 and SHA1 encryption class library!
The following are two cryptographic methods for calling this class library:

=====================

public string GetMD5 (string strdata)
{
Using the MD5 encryption method:
System.Security.Cryptography.MD5 MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
byte[] md5bytes = System.Text.Encoding.Default.GetBytes (strdata);
byte[] crystring = Md5.computehash (md5bytes);
String md5str = String. Empty;
for (int i=0;i<crystring.length;i++)
{
Md5str + = Crystring[i]. ToString ("X2");
}
return md5str;
}

public string Getencrypt (String strdata,string strtype)
{
Use the MD5 or SHA1 encryption method:
String strcrydata = String. Empty;
if (strtype.toupper () = = "SHA1")
{
Strcrydata = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (strdata, "SHA1");
}
else if (strtype.toupper () = = "MD5")
{
Strcrydata = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (strdata, "MD5");
}
return strcrydata;
}




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.