public void EncryptTest3() { var x = new XrdEncryptor(Keys1.Item1); DateTime clear = DateTime.Now; byte[] bClear = BitConverter.GetBytes(clear.Ticks); byte[] mixed1 = x.Encrypt(clear); byte[] mixed2 = x.Encrypt(clear, Keys1.Item2); // Verify all arrays are different. Assert.IsTrue(bClear.HasChanges(mixed1)); Assert.IsTrue(bClear.HasChanges(mixed2)); Assert.IsTrue(mixed2.HasChanges(mixed1)); // Check decryption. Assert.IsFalse(clear.HasChanges(x.DecryptToDateTime(mixed1))); Assert.IsFalse(clear.HasChanges(x.DecryptToDateTime(mixed2, Guid.NewGuid()))); // Should fail - wrong key. Assert.IsFalse(clear.HasChanges(x.DecryptToDateTime(mixed2, Guid.NewGuid()))); // Verify gets result but wrong with different encryptor with different key. var x1 = new XrdEncryptor(Keys2.Item1); Assert.IsTrue(clear.HasChanges(x1.DecryptToDateTime(mixed1))); // Verify decryption with new encryptor instance. var x2 = new XrdEncryptor(Keys1.Item1); Assert.IsFalse(clear.HasChanges(x2.DecryptToDateTime(mixed1))); Assert.IsFalse(clear.HasChanges(x2.DecryptToDateTime(mixed2, Keys1.Item2))); var mixed3 = x.Encrypt(clear, Keys2.Item2); Assert.IsFalse(clear.HasChanges(x.DecryptToDateTime(mixed3, Keys2.Item2))); }
public void EncryptTest() { var x = new XrdEncryptor(Keys1.Item1); byte[] clear = null; Assert.ThrowsException <ArgumentNullException>(() => x.Encrypt(clear)); Random r = new Random(); clear = new byte[100]; r.NextBytes(clear); byte[] mixed1 = x.Encrypt(clear); byte[] mixed2 = x.Encrypt(clear, toArray(Keys1)); // Verify all arrays are different. Assert.IsTrue(clear.HasChanges(mixed1)); Assert.IsTrue(clear.HasChanges(mixed2)); Assert.IsTrue(mixed2.HasChanges(mixed1)); // Check decryption. Assert.IsFalse(clear.HasChanges(x.Decrypt(mixed1))); Assert.IsFalse(clear.HasChanges(x.Decrypt(mixed2, toArray(Keys1)))); // Should fail - wrong key. Assert.IsTrue(clear.HasChanges(x.Decrypt(mixed2, Keys1.Item1))); // Verify gets result but wrong with different encryptor with different key. var x1 = new XrdEncryptor(Keys2.Item1); Assert.IsTrue(clear.HasChanges(x1.Decrypt(mixed1))); // Verify decryption with new encryptor instance. var x2 = new XrdEncryptor(Keys1.Item1); Assert.IsFalse(clear.HasChanges(x2.Decrypt(mixed1))); Assert.IsFalse(clear.HasChanges(x2.Decrypt(mixed2, toArray(Keys1)))); }
public void EncryptTest2() { var x = new XrdEncryptor(Keys1.Item1); string clear = null; Assert.ThrowsException <ArgumentNullException>(() => x.Encrypt(clear)); clear = "This is some secret that I want to hide."; Console.WriteLine("Clear:\t{0}", clear); byte[] bClear = Encoding.UTF8.GetBytes(clear); byte[] mixed1 = x.Encrypt(clear); byte[] mixed2 = x.Encrypt(clear, toArray(Keys1)); // Verify all arrays are different. Assert.IsTrue(bClear.HasChanges(mixed1)); Assert.IsTrue(bClear.HasChanges(mixed2)); Assert.IsTrue(mixed2.HasChanges(mixed1)); // Check decryption. string d1 = x.DecryptToString(mixed1); Assert.IsFalse(clear.HasChanges(d1)); Console.WriteLine("D1:\t{0}", d1); string d2 = x.DecryptToString(mixed2, toArray(Keys1)); Assert.IsFalse(clear.HasChanges(d2)); Console.WriteLine("D2:\t{0}", d2); // Should fail - wrong key. string w1 = x.DecryptToString(mixed2, Keys1.Item1); Assert.IsTrue(clear.HasChanges(w1)); Console.WriteLine("Wrong1:\t{0}", w1); // Should fail - not enough keys string w2 = x.DecryptToString(mixed2, Keys1.Item2); Assert.IsTrue(clear.HasChanges(w2)); Console.WriteLine("Wrong2:\t{0}", w2); // Verify gets result but wrong with different encryptor with different key. var x1 = new XrdEncryptor(Keys2.Item1); Assert.IsTrue(clear.HasChanges(x1.DecryptToString(mixed1))); // Verify decryption with new encryptor instance. var x2 = new XrdEncryptor(Keys1.Item1); Assert.IsFalse(clear.HasChanges(x2.DecryptToString(mixed1))); Assert.IsFalse(clear.HasChanges(x2.DecryptToString(mixed2, toArray(Keys1)))); var mixed3 = x.Encrypt(clear, Keys2.Item2); Assert.IsFalse(clear.HasChanges(x.DecryptToString(mixed3, Keys2.Item2))); }
public void EncryptTest1() { var x = new XrdEncryptor(Keys2.Item1); byte[] clear = null; Assert.ThrowsException <ArgumentNullException>(() => x.Encrypt(clear)); Random r = new Random(); clear = new byte[100]; r.NextBytes(clear); byte[] mixed1 = x.Encrypt(clear); byte[] mixed2 = x.Encrypt(clear, Keys2.Item2); Assert.IsTrue(clear.HasChanges(mixed1)); Assert.IsTrue(clear.HasChanges(mixed2)); Assert.IsTrue(mixed2.HasChanges(mixed1)); Assert.IsFalse(clear.HasChanges(x.Decrypt(mixed1))); Assert.IsFalse(clear.HasChanges(x.Decrypt(mixed2, Keys2.Item2))); }