示例#1
0
        /// <summary>
        /// Encodes a cookie
        /// </summary>
        /// <param name="cookie">The cookie to encode</param>
        /// <param name="cookieProtection">The cookie protection to set</param>
        /// <returns>A clone of the cookie in encoded format</returns>
        public static HttpCookie Encode(HttpCookie cookie, CookieProtection cookieProtection)
        {
            HttpCookie encodedCookie = CloneCookie(cookie);

            encodedCookie.Value = MachineKeyCryptography.Encode(cookie.Value, cookieProtection);
            return(encodedCookie);
        }
示例#2
0
 /// <summary>
 /// Decodes a cookie. Throws InvalidCypherTextException if unable to decode.
 /// </summary>
 /// <param name="cookie">The cookie to decode</param>
 /// <param name="cookieProtection">The protection level to use when decoding</param>
 /// <returns>A clone of the cookie in decoded format</returns>
 public static HttpCookie Decode(HttpCookie cookie, CookieProtection cookieProtection)
 {
     try
     {
         HttpCookie decodedCookie = CloneCookie(cookie);
         decodedCookie.Value = MachineKeyCryptography.Decode(cookie.Value, cookieProtection);
         return(decodedCookie);
     }
     catch
     {
         return(null);
     }
 }