예제 #1
0
        public void TestAESEncryption()
        {
            EncryptionService ES = new EncryptionService();

            string plaintext = "Hello World!";

            Tuple <string, string, string> keyInfo1 = ES.AESEncrypt(plaintext);

            Assert.AreNotEqual(keyInfo1.Item1, plaintext);
            Assert.AreNotEqual(keyInfo1.Item2, plaintext);
            Assert.AreNotEqual(keyInfo1.Item3, plaintext);
            string decrypted1 = ES.AESDecrypt(keyInfo1.Item1, keyInfo1.Item2, keyInfo1.Item3);

            Assert.AreEqual(plaintext, decrypted1);

            Tuple <string, string, string> keyInfo2 = ES.AESEncrypt(plaintext);

            Assert.AreNotEqual(keyInfo2.Item1, plaintext);
            Assert.AreNotEqual(keyInfo2.Item2, plaintext);
            Assert.AreNotEqual(keyInfo2.Item3, plaintext);
            string decrypted2 = ES.AESDecrypt(keyInfo2.Item1, keyInfo2.Item2, keyInfo2.Item3);

            Assert.AreEqual(plaintext, decrypted2);

            // Make sure we are not encrypted the same message the same way twice
            Assert.AreNotEqual(keyInfo1.Item1, keyInfo2.Item1);
            Assert.AreNotEqual(keyInfo1.Item2, keyInfo2.Item2);
            Assert.AreNotEqual(keyInfo1.Item3, keyInfo2.Item3);
        }