public void TestSaltedDataWithSpecificSize() { Salt s = new Salt(Salt.Size.b64); byte[] testData = new byte[8]; new Random().NextBytes(testData); byte[] tmp; using (SaltedData sd = new SaltedData(s, testData)) { Assert.AreEqual(16, sd.Length); Assert.AreEqual(s, sd.Salt); Assert.AreEqual(testData, sd.GetDataBytes()); tmp = sd.ToArray(); Assert.AreEqual(16, tmp.Length); Assert.AreEqual(tmp, IOStream.ReadAllBytes(sd.ToStream())); } using (SaltedData sd = new SaltedData(s, new MemoryStream(testData))) { Assert.AreEqual(s, sd.Salt); Assert.AreEqual(testData, sd.GetDataBytes()); Assert.AreEqual(tmp, sd.ToArray()); } using (SaltedData sd = new SaltedData(tmp, Salt.Size.b64)) { Assert.AreEqual(s, sd.Salt); Assert.AreEqual(testData, sd.GetDataBytes()); Assert.AreEqual(tmp, sd.ToArray()); } }
public void TestSaltGetData() { Salt s = new Salt(); byte[] bytes = new byte[1024]; new Random().NextBytes(bytes); SaltedData sd = s.GetData(bytes); Assert.AreEqual(s, sd.Salt); Assert.AreEqual(bytes, sd.GetDataBytes()); sd = s.GetData(new MemoryStream(bytes)); Assert.AreEqual(s, sd.Salt); Assert.AreEqual(bytes, sd.GetDataBytes()); }
public void TestSaltedDataStream() { Salt s = new Salt(Salt.Size.b64); byte[] testData = new byte[8]; byte[] test1 = new SaltedData(s, testData).ToArray(); Assert.AreEqual(16, test1.Length); byte[] test2 = IOStream.ReadAllBytes(new SaltedData(s, testData).ToStream()); Assert.AreEqual(16, test2.Length); byte[] test3 = IOStream.ReadAllBytes(SaltedData.CombineStream(s, new MemoryStream(testData))); Assert.AreEqual(16, test3.Length); Assert.AreEqual(test1, test2); Assert.AreEqual(test1, test3); Assert.AreEqual(test2, test3); }