Ejemplo n.º 1
0
        public void EncryptDecryptData()
        {
            var encrypted = Aes.EncryptByteArray(Encoding.Default.GetBytes(DecryptedMessage), Key);
            var decrypted = Aes.DecryptByteArray(encrypted, Key);

            Assert.NotNull(encrypted);
            Assert.NotNull(decrypted);
            Assert.Equal(DecryptedMessage, decrypted);
        }
Ejemplo n.º 2
0
        public void EncryptData()
        {
            var encrypted = Aes.EncryptByteArray(Encoding.Default.GetBytes(DecryptedMessage), Key);

            Assert.NotNull(encrypted);
            Assert.Equal(EncryptedMessage.Length, encrypted.Length);

            for (int i = 0; i < EncryptedMessage.Length; i++)
            {
                Assert.Equal(EncryptedMessage[i], encrypted[i]);
            }
        }
Ejemplo n.º 3
0
        public void EncryptDecryptByteArrayWithGeneratedKey(int keySize)
        {
            byte[] decryptedMessageBytes = Encoding.UTF8.GetBytes(DecryptedMessage);
            byte[] generatedKey          = Convert.FromBase64String(Aes.GenerateKey(keySize));
            byte[] encryptedData         = Aes.EncryptByteArray(decryptedMessageBytes, generatedKey);

            Assert.NotNull(encryptedData);

            string decryptedData = Aes.DecryptByteArray(encryptedData, generatedKey);

            Assert.NotNull(decryptedData);
            Assert.Equal(DecryptedMessage, decryptedData);
        }