Ejemplo n.º 1
0
        public void Decrypting_data_that_could_not_possibly_be_encrypted_should_return_null()
        {
            /* Arrange */
            byte[] sourceTooSmall = new byte[4];
            var crypto = new AesCryptoProvider();

            /* Act */
            bool isEncrypted = crypto.IsEncrypted(sourceTooSmall);

            var decryptedVale = crypto.Decrypt(sourceTooSmall);

            /* Assert */
            decryptedVale.Should().BeNull();
            isEncrypted.Should().BeFalse();
        }
Ejemplo n.º 2
0
        public void Encrypting_and_decrypting_a_string_with_aes_should_work()
        {
            /* Arrange */
            string source = "SomeValue";
            var crypto = new AesCryptoProvider();

            /* Act */
            string encryptedValue = crypto.Encrypt(source);

            bool isEncrypted = crypto.IsEncrypted(encryptedValue);

            string decryptedVale = crypto.Decrypt(encryptedValue);

            /* Assert */
            encryptedValue.Should().NotBe(source);
            decryptedVale.Should().Be(source);
            isEncrypted.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void Encrypting_and_decrypting_null_or_empty_string_should_work()
        {
            /* Arrange */
            var crypto = new AesCryptoProvider();

            /* Act */
            string nullStringEncrypt = crypto.Encrypt((string)null);
            string emptyStringEncrypt = crypto.Encrypt(string.Empty);
            byte[] nullByteEncrypt = crypto.Encrypt((byte[])null);

            bool isEncryptedNullString = crypto.IsEncrypted((string)null);
            bool isEncryptedEmptyString = crypto.IsEncrypted(string.Empty);
            bool isEncryptedNullByte = crypto.IsEncrypted((byte[])null);

            string nullStringDecrypt = crypto.Decrypt((string)null);
            string emptyStringDecrypt = crypto.Decrypt(string.Empty);
            byte[] nullByteDecrypt = crypto.Decrypt((byte[])null);

            /* Assert */
            nullStringEncrypt.Should().BeNull();
            emptyStringEncrypt.Should().BeEmpty();
            nullByteEncrypt.Should().BeNull();

            isEncryptedNullString.Should().BeFalse();
            isEncryptedEmptyString.Should().BeFalse();
            isEncryptedNullByte.Should().BeFalse();

            nullStringDecrypt.Should().BeNull();
            emptyStringDecrypt.Should().BeEmpty();
            nullByteDecrypt.Should().BeNull();
        }