Ejemplo n.º 1
0
        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))));
        }
Ejemplo n.º 2
0
        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)));
        }