public void WhenByteArrayThenDecryptAfterEncryptShouldReturnSameData()
        {
            //Arrange
            byte[] data = new byte[256];

            Random random = new Random((int)DateTime.Now.Ticks);

            random.NextBytes(data);

            string password = "******";
            string salt     = "[email protected]";

            //Act
            byte[] encriptedData = SymmetricCryptoUtil.Encrypt(data, password, salt);
            byte[] decriptedData = SymmetricCryptoUtil.Decrypt(encriptedData, password, salt);

            //Assert
            Assert.IsNotNull(encriptedData);
            Assert.IsNotNull(decriptedData);

            Assert.AreNotEqual(0, encriptedData.Length);
            Assert.AreNotEqual(0, decriptedData.Length);

            CollectionAssert.AreEqual(data, decriptedData);
            CollectionAssert.AreNotEqual(encriptedData, data);
        }
        public void WhenTextThenDecryptAfterEncryptShouldReturnSameData()
        {
            //Arrange
            string text = "This is a sample string with some diacritics: áâàâãç";

            string password = "******";
            string salt     = "[email protected]";

            //Act
            var encriptedText = SymmetricCryptoUtil.EncryptText(text, password, salt);
            var decriptedText = SymmetricCryptoUtil.DecryptText(encriptedText, password, salt);

            //Assert
            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);

            Assert.AreNotEqual(0, encriptedText.Length);
            Assert.AreNotEqual(0, decriptedText.Length);

            Assert.AreEqual(text, decriptedText);
            Assert.AreNotEqual(encriptedText, text);
        }
 public void WhenSaltIsEmptyThenDecryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { 10, 42 }, "some random password", string.Empty));
 }
 public void WhenPasswordIsNullThenDecryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { 10, 42 }, null, "some random salt"));
 }
 public void WhenDataIsEmptyNullThenDecryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { }, "some random password", "some random salt"));
 }
 public void WhenSaltIsNullThenEncryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Encrypt(new byte[] { 10, 42 }, "some random password", null));
 }
 public void WhenPasswordIsEmptyThenEncryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Encrypt(new byte[] { 10, 42 }, string.Empty, "some random salt"));
 }
 public void WhenDataIsNullThenEncryptShouldThrowArgumentNullException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Encrypt(null, "some random password", "some random salt"));
 }