Ejemplo n.º 1
0
 /// <summary>
 /// Encodes a string
 /// </summary>
 /// <param name="text">String to encode</param>
 /// <param name="cookieProtection">The method in which the string is protected</param>
 /// <returns></returns>
 public static string Encode(string text, CookieProtection cookieProtection)
 {
     if (string.IsNullOrEmpty(text) || cookieProtection == CookieProtection.None)
     {
         return(text);
     }
     byte[] buf = Encoding.UTF8.GetBytes(text);
     return(CookieProtectionHelperWrapper.Encode(cookieProtection, buf, buf.Length));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Decodes a string
 /// </summary>
 /// <param name="text">String to decode</param>
 /// <param name="cookieProtection">The method in which the string is protected</param>
 /// <returns>The decoded string or throws InvalidCypherTextException if tampered with</returns>
 public static string Decode(string text, CookieProtection cookieProtection)
 {
     if (string.IsNullOrEmpty(text))
     {
         return(text);
     }
     byte[] buf;
     try {
         buf = CookieProtectionHelperWrapper.Decode(cookieProtection, text);
     }
     catch (Exception ex) {
         throw new InvalidCypherTextException("Unable to decode the text", ex.InnerException);
     }
     if (buf == null || buf.Length == 0)
     {
         throw new InvalidCypherTextException("Unable to decode the text");
     }
     return(Encoding.UTF8.GetString(buf, 0, buf.Length));
 }