C #. Net cookie operation key uses MD5 encryption, and value uses AES Encryption

Source: Internet
Author: User

 

  Using  System;
Using System. text;
Using System. Web;

Namespace Pub. Class
{
/// <Summary>
/// Cookie operation
/// </Summary>
Public Class Cookie2
{
# Region Set
/// <Summary>
/// Set cookies
/// </Summary>
/// <Param name = "infoname"> Cookie name </Param>
/// <Param name = "infovalue"> Cookie name value </Param>
Static Public Void Set (string infoname, string infovalue) {set ( " Info " , Infoname, infovalue, 0 );}
/// <Summary>
/// Set cookies
/// </Summary>
/// <Param name = "Index"> Index </Param>
/// <Param name = "infoname"> Cookie name </Param>
/// <Param name = "infovalue"> Cookie name value </Param>
Static Public Void Set ( String Index, string infoname, string infovalue) {set (index, infoname, infovalue, 0 );}

/// <Summary>
/// Set cookies
/// </Summary>
/// <Param name = "infoname"> Cookie name </Param>
/// <Param name = "infovalue"> Cookie name value </Param>
/// <Param name = "dates"> Validity period days </Param>
Static Public Void Set (string infoname, string infovalue, Int Dates) {set ( " Info " , Infoname, infovalue, dates );}
/// <Summary>
/// Set cookies
/// </Summary>
/// <Param name = "Index"> Index </Param>
/// <Param name = "infoname"> Cookie name </Param>
/// <Param name = "infovalue"> Cookie name value </Param>
/// <Param name = "dates"> Validity period days </Param>
Static Public Void Set ( String Index, string infoname, string infovalue, Int Dates ){
String Key = " 9cf8d21d394a8919d2f9706dfdc6421e " ;
Index = (Key + Index). MD5 ();
Infoname = (Key + Infoname). MD5 ();
Infovalue = Infovalue. aesencode (key );
If (Dates > 0 ) Httpcontext. Current. response. Cookies [Index]. Expires = Datetime. Now. adddays (dates );
Httpcontext. Current. response. Cookies [Index] [infoname] = Infovalue;
}
# Endregion

# Region Get
/// <Summary>
/// Cookies
/// </Summary>
/// <Param name = "infoname"> Cookie name </Param>
/// <Returns> Cookie name value </Returns>
Static Public String get (string infoname ){ Return Get ( " Info " , Infoname );}
/// <Summary>
/// Cookies
/// </Summary>
/// <Param name = "Index"> Index </Param>
/// <Param name = "infoname"> Cookie name </Param>
/// <Returns> Cookie name value </Returns>
Static Public String get ( String Index, string infoname ){
String _ Value = String . Empty;
String Key = " 9cf8d21d394a8919d2f9706dfdc6421e " ;
Index = (Key + Index). MD5 ();
Infoname = (Key + Infoname). MD5 ();

If (Httpcontext. Current. Request. Cookies [Index] ! = Null ){
If (Httpcontext. Current. Request. Cookies [Index] [infoname] ! = Null ){
_ Value = Httpcontext. Current. Request. Cookies [Index] [infoname]. tostring ();
_ Value = _ Value. aesdecode (key );
}
}
Return _ Value;
}
# Endregion
}
}

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.