예제 #1
0
 public void EncryptWithExistingKeyIVData()
 {
     using (var aes = new AesWrapper(KeyData, IVData))
     {
         TestEncryption(aes);
     }
 }
예제 #2
0
        public void EncryptWithExistingKeyNewIV()
        {
            using (var aes = new AesWrapper(KeyData))
            {
                var iv = ConvertWrapper.ToHexString(aes.CreateIV());
                Assert.That(!string.IsNullOrEmpty(iv));
                Log.Info("IV: {0}", iv);

                TestEncryption(aes);
            }
        }
예제 #3
0
        private static void TestEncryption(AesWrapper aes)
        {
            const string stringToEncrypt = "hello, encrypted world!!!";

            var encrypted = aes.EncryptToString(stringToEncrypt);
            Assert.That(encrypted != null);
            Log.Info("Encrypted: {0}", encrypted);

            var decrypted = aes.DecryptFromString(encrypted);
            Assert.That(stringToEncrypt == decrypted);

            encrypted = aes.EncryptAsHexString(stringToEncrypt);
            Assert.That(encrypted != null);
            Log.Info("Encrypted: {0}", encrypted);

            decrypted = aes.DecryptFromHexString(encrypted);
            Assert.That(stringToEncrypt == decrypted);

            var encryptedData = aes.Encrypt(stringToEncrypt);
            Assert.That(encryptedData != null);
            var decryptedData = aes.Decrypt(encryptedData);
            Assert.That(decryptedData != null);
            Assert.That(Encoding.Unicode.GetString(decryptedData) == stringToEncrypt);
        }
예제 #4
0
        public void EncryptWithNewKeyIV()
        {
            using (var aes = new AesWrapper())
            {
                var key = ConvertWrapper.ToHexString(aes.CreateKey());
                Assert.That(!string.IsNullOrEmpty(key));
                Log.Info("Key: {0}", key);

                var iv = ConvertWrapper.ToHexString(aes.CreateIV());
                Assert.That(!string.IsNullOrEmpty(iv));
                Log.Info("IV: {0}", iv);

                TestEncryption(aes);
            }
        }