public static byte[] Compress(byte[] input) { MemoryStream stream = new MemoryStream(input); DeflateStream compressStream = new DeflateStream(stream, CompressionMode.Compress); return(compressStream.ReadAllBytes()); }
public static byte[] Decompress(byte[] input) { // two bytes shaved off (zlib header) var sourceStream = new MemoryStream(input, 2, input.Length - 2); var stream = new DeflateStream(sourceStream, CompressionMode.Decompress); return(stream.ReadAllBytes()); }
public static AuthToken DeserializeToken(string token) { try { var array = Convert.FromBase64String(token); array = Decrypt(array); using (var ms = new MemoryStream(array)) using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress)) { var bytes = ds.ReadAllBytes(); return(JsonExtensions.FromJsonBytes <AuthToken>(bytes, EntityJsonContext.FullJsonSerializerOptions)); } } catch (Exception) { throw new AuthenticationException("Invalid token"); } }