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 WhenPasswordIsNullThenDecryptShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { 10, 42 }, null, "some random salt")); }
public void WhenSaltIsEmptyThenDecryptShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { 10, 42 }, "some random password", string.Empty)); }
public void WhenDataIsEmptyNullThenDecryptShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => SymmetricCryptoUtil.Decrypt(new byte[] { }, "some random password", "some random salt")); }