/// <summary> /// Sets the value of the key within the CG cookie. The value is encrypted before being set. /// </summary> /// <param name="context"></param> /// <param name="keyName"></param> /// <param name="value"></param> public static void SetCookieValueString(HttpContextBase context, string keyName, string value) { HttpCookie cookie = null; //See if the response has a cookie. if (!context.Response.Cookies.AllKeys.Contains(Constants.CookieName)) { //If the request has a cookie, lets copy it to the response if (context.Request.Cookies.AllKeys.Contains(Constants.CookieName)) { cookie = context.Request.Cookies[Constants.CookieName]; context.Response.AppendCookie(cookie); } else { cookie = AddCookie(context); } } else { cookie = context.Response.Cookies[Constants.CookieName]; } SymmetricCipherResults cipherResults = EncryptData(value); cookie[keyName] = string.Format("{0},{1}", cipherResults.IV, cipherResults.CipherText); }
public static string DecryptData(SymmetricCipherResults cipherResults) { return(SymmetricOperation.DecryptData(cipherResults, Constants.Cookie_SymmetricAlgorithm, Constants.Cookie_SymmetricKey)); }