/// <summary> /// Decrypts the ticket /// </summary> /// <param name="cookieString"></param> /// <returns></returns> public FormsAuthenticationTicket DecryptCookie(string cookieString) { byte[] cookieBlob = null; // 1. Convert from hex to binary. if ((cookieString.Length % 2) == 0) { // Could be a hex string try { cookieBlob = HexUtils.HexToBinary(cookieString); } catch { } } if (cookieBlob == null) { return(null); } // decrypt byte[] decryptedCookie = Decrypt(cookieBlob, _hasher, true); int ticketLength = decryptedCookie.Length; if (_CompatibilityMode == CompatibilityMode.Framework20SP2) { ticketLength = decryptedCookie.Length - _hasher.HashSize; bool validHash = _hasher.CheckHash(decryptedCookie, ticketLength); if (!validHash) { throw new Exception("Invalid Hash"); } } return(FormsAuthenticationTicketHelper.Deserialize(decryptedCookie, ticketLength)); }
public FormsAuthenticationTicketEncryptor( string decryptionKey, string validationKey, DecryptionKeyAlgorithm decryptionKeyAlgorithm, ValidationKeyAlgorithm validationKeyAlgorithm, CompatibilityMode compatibilityMode) { byte[] descriptionKeyBytes = HexUtils.HexToBinary(decryptionKey); byte[] validationKeyBytes = HexUtils.HexToBinary(validationKey); Initialize(descriptionKeyBytes, validationKeyBytes, decryptionKeyAlgorithm, validationKeyAlgorithm, compatibilityMode); }