public void EncryptWithExistingKeyIVData() { using (var aes = new AesWrapper(KeyData, IVData)) { TestEncryption(aes); } }
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); } }
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); }
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); } }