Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i am trying to encrypt a cookie (name and value) and then restore its value

i am trying this code but there is a problem its always get null.

C#
public class Auth
{
    public static string Lang
    {
        get
        {
            if (HttpContext.Current.Request.Cookies[Encryption.Encrypt("Lang")] == null || HttpContext.Current.Request.Cookies[Encryption.Encrypt("Lang")].Value == null) return null;
            return Encryption.Decrypt( HttpContext.Current.Request.Cookies[Encryption.Encrypt("Lang")].Value);
        }
        set
        {
            HttpCookie s = new HttpCookie(Encryption.Encrypt("Lang"), Encryption.Encrypt( value));
            s.Expires = DateTime.Now.AddYears(1);
            HttpContext.Current.Response.Cookies.Add(s);
        }
    }

    public static bool IsArabic { get { return Lang == "Arabic" && Lang != null; } }
    public static bool IsEnglish { get { return Lang != "Arabic" && Lang != null; } }




}



when i use the cookie :

Auth.Lang = "English";


test the cookie :

if(Auth.IsEnglish)



but always get null ... can anyone help ?
Posted
Comments
Gideon van Dyk 3-Feb-15 16:44pm    
I take it this Encryption library isn't one of the standard .NET libraries. Some more information might be helpful like your using declarations and what component you are using.
ENG.Samy Sammour 3-Feb-15 17:08pm    
Its a code i write it and its works 100% true

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900