asp.net code for the encryption and decryption of Chinese characters _ practical skills

Source: Internet
Author: User
Tags decrypt md5 md5 encryption sha1 sha1 encryption

Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
Encryption algorithm
String username = "I am Chen Jianyong";
MD5 Encryption-Get 32-bit encrypted data, hard to decrypt data. Too complex.
Username =formsauthentication.hashpasswordforstoringinconfigfile (username, "MD5");
SHA1 Encryption-Get 40-bit encrypted data, hard to decrypt data. Too complex.
String username1 = FormsAuthentication.HashPasswordForStoringInConfigFile (username, "SHA1");
Response.Write (username+ "<br>");
Response.Write (username1+ "<br>");
Decryption algorithm
General encryption
string s = "I am Chen Jianyong";
String encodestr = "";
byte[] bytes = System.Text.Encoding.GetEncoding (0). GetBytes (s);
Try
{
encodestr = convert.tobase64string (bytes);
Response.Write ("AA");
}
Catch
{
Encodestr = s;
Response.Write ("BB");
}
Response.Write (encodestr+ "<br>");
General decryption
String decodestr = "";
byte[] bytes1 = convert.frombase64string (ENCODESTR);
Try
{
Decodestr = System.Text.Encoding.GetEncoding (0). GetString (BYTES1);
Response.Write ("CC");
}
Catch
{
Response.Write ("DD");
Decodestr = Encodestr;
}
Response.Write (decodestr+ "<br>");
General encryption
String myname = "Chen Jianyong";
MyName = System.Web.HttpUtility.UrlEncode (myname, System.Text.Encoding.UTF8);
Response.Write (myname+ "<br>");
General decryption
MyName = System.Web.HttpUtility.UrlDecode (myname, System.Text.Encoding.UTF8);
Response.Write (myname);
}

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.