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