Beispiel #1
0
        public void Test_Encrypt()
        {
            var cipherWithFixedIv = new AeadAes256CbcHmacSha512Cipher(new FakeRandomNumberGenerator(Iv));
            var actualCiphertext  = cipherWithFixedIv.Encrypt(Key, Plaintext, AssociatedData);

            Assert.Equal(CipherText, actualCiphertext);
        }
Beispiel #2
0
        public void Test_WorksWithRealIvGenerator()
        {
            var cipherWithRandomIv = new AeadAes256CbcHmacSha512Cipher();
            var cipherText         = cipherWithRandomIv.Encrypt(Key, Plaintext, AssociatedData);
            var roundTripPlainText = cipherWithRandomIv.Decrypt(Key, cipherText, AssociatedData);

            Assert.Equal(Plaintext, roundTripPlainText);
        }
Beispiel #3
0
        public void Test_AssociatedDataCanBeEmpty()
        {
            var emptyByteArray     = Array.Empty <byte>();
            var cipherWithFixedIv  = new AeadAes256CbcHmacSha512Cipher(new FakeRandomNumberGenerator(emptyByteArray));
            var cipherText         = cipherWithFixedIv.Encrypt(Key, Plaintext, emptyByteArray);
            var roundTripPlainText = new AeadAes256CbcHmacSha512Cipher().Decrypt(Key, cipherText, emptyByteArray);

            Assert.Equal(Plaintext, roundTripPlainText);
        }
Beispiel #4
0
        public void Test_EncryptBadKeySize()
        {
            var cipherWithFixedIv = new AeadAes256CbcHmacSha512Cipher(new FakeRandomNumberGenerator(Iv));

            Assert.Throws <InvalidCryptoKeyException>(() => cipherWithFixedIv.Encrypt(new byte[0], CipherText, AssociatedData));
        }