예제 #1
0
        public static byte[] Compress(byte[] input)
        {
            MemoryStream  stream         = new MemoryStream(input);
            DeflateStream compressStream = new DeflateStream(stream, CompressionMode.Compress);

            return(compressStream.ReadAllBytes());
        }
예제 #2
0
        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());
        }
예제 #3
0
        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");
            }
        }