示例#1
0
        public void AesSimple_EmptyData_Test()
        {
            //Arrange
            byte[] byteInput = new Byte[0];
            var    aes       = new AesSimple();

            //Act
            //Assert
            Assert.ThrowsException <ArgumentException>(() => aes.EncryptBytes(byteInput, EncryptionKey), "data cannot be empty");
        }
示例#2
0
        public void AesSimple_IncorrectKeySize_Test()
        {
            //Arrange
            var input = "This is some unencrypted text that we are going to encrypt then decrypt to make sure it comes out correct.";
            //Convert from string to byte array
            var byteInput = Encoding.UTF8.GetBytes(input);
            var shortkey  = new byte[24];
            var aes       = new AesSimple();

            //Act
            //Assert
            Assert.ThrowsException <ArgumentException>(() => aes.EncryptBytes(byteInput, shortkey), "encryptionKey must be 256 bits");
        }
示例#3
0
        public void AesSimple_HappyPath_Test()
        {
            //Arrange
            var input = "This is some unencrypted text that we are going to encrypt then decrypt to make sure it comes out correct.";
            //Convert from string to byte array
            var byteInput = Encoding.UTF8.GetBytes(input);
            var aes       = new AesSimple();
            //Act
            var encryptedString = aes.EncryptBytes(byteInput, EncryptionKey);
            var byteOutput      = aes.DecryptBytes(encryptedString, EncryptionKey);
            //Convert from byte array to string
            var output = Encoding.UTF8.GetString(byteOutput, 0, byteOutput.Length);

            //Assert
            Assert.AreEqual(input, output);
        }