public void TestSafe64StreamRead() { string encoded = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; byte[] data = Safe64Encoding.DecodeBytes(encoded); byte[] test; using (Stream io = new Safe64Stream(new MemoryStream(Encoding.ASCII.GetBytes(encoded)), CryptoStreamMode.Read)) test = IOStream.Read(io, data.Length); Assert.AreEqual(data, test); }
public void TestSafe64StreamWrite() { byte[] data = new byte[222]; new Random().NextBytes(data); using (Stream mem = new MemoryStream()) { using (Stream io = new Safe64Stream(new NonClosingStream(mem), CryptoStreamMode.Write)) io.Write(data, 0, data.Length); Assert.AreEqual((long)Math.Ceiling((data.Length * 8) / 6d), mem.Position); mem.Position = 0; string test = new StreamReader(mem).ReadToEnd(); Assert.AreEqual(Safe64Encoding.EncodeBytes(data), test); } }