public static StreamReader Decrypt(string source, int key) { byte[] data = System.Convert.FromBase64String(source); byte[] dec = AES.DecryptData(data, GetTrueKey(key), key.ToString() + "P8xvDLzPHvNiwVMkS3kPzQStAEDqdTMD", System.Security.Cryptography.PaddingMode.ISO10126); int d_len = System.BitConverter.ToInt32(dec, 40); MemoryStream ms = new MemoryStream(dec); ms.Position = 44; // Use the newly created memory stream for the compressed data. DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Decompress, true); //Console.WriteLine("Compression"); byte[] zdec = new byte[d_len]; int cnt = compressedzipStream.Read(zdec, 0, d_len); // Close the stream. compressedzipStream.Close(); dec = new byte[cnt]; System.Array.ConstrainedCopy(zdec, 0, dec, 0, cnt); MemoryStream mem_stream = new MemoryStream(dec); StreamReader output = new StreamReader(mem_stream); return(output); }
public static byte[] Decrypt(byte[] data, string key, string salt) { byte[] dec; try { dec = AES.DecryptData(data, key, salt, System.Security.Cryptography.PaddingMode.ISO10126); } catch (Exception e) { throw e; } int d_len = System.BitConverter.ToInt32(dec, 0); System.IO.MemoryStream ms = new System.IO.MemoryStream(dec); ms.Position = 4; // Use the newly created memory stream for the compressed data. DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Decompress, true); //Console.WriteLine("Compression"); byte[] zdec = new byte[d_len]; int cnt = compressedzipStream.Read(zdec, 0, d_len); // Close the stream. compressedzipStream.Close(); ms.Close(); dec = new byte[cnt]; System.Array.ConstrainedCopy(zdec, 0, dec, 0, cnt); zdec = null; return(dec); }