Ejemplo n.º 1
0
        public async void Encrypt_Test_Resulting_String_Format(string input)
        {
            var crypto = new AesBasicCrypto_StorageOverride("FakeApples");

            var result = await crypto.Encrypt(input);

            Assert.Equal(2, result?.Split(';').Length);
        }
Ejemplo n.º 2
0
        public async void Decrypt(string encrypted, string password, string decrypted)
        {
            var crypto = new AesBasicCrypto_StorageOverride(password);

            // Used to build the inline data for this test.
            //var r = await crypto.Encrypt(decrypted);
            //System.Diagnostics.Debug.WriteLine($"[InlineData(\"{r}\", \"{password}\" ,\"{decrypted}\")]");

            var result = await crypto.Decrypt(encrypted);

            Assert.Equal(decrypted, result);
        }
Ejemplo n.º 3
0
        public async void Decrypt_With_Invalid_Password_Throws_InvalidPasswordException(string decryptPassword, string encryptPassword, string text)
        {
            var crypto = new AesBasicCrypto_StorageOverride(encryptPassword);

            var encrypted = await crypto.Encrypt(text);

            Assert.NotNull(encrypted);
            Assert.False(string.IsNullOrEmpty(encrypted));

            crypto = new AesBasicCrypto_StorageOverride(decryptPassword);

            await Assert.ThrowsAsync <InvalidPasswordException>(async() => await crypto.Decrypt(encrypted !));
        }
Ejemplo n.º 4
0
        public async void Round_Trip(string password, string text)
        {
            var crypto = new AesBasicCrypto_StorageOverride(password);

            var encrypted = await crypto.Encrypt(text);

            if (!string.IsNullOrEmpty(encrypted))
            {
                Assert.NotEqual(text, encrypted);
            }

            var decrypted = await crypto.Decrypt(encrypted !);

            Assert.Equal(text, decrypted);
        }
Ejemplo n.º 5
0
        public async void Encrypt_With_Empty_Password_Throws_InvalidPasswordException()
        {
            var crypto = new AesBasicCrypto_StorageOverride(Array.Empty <byte>());

            await Assert.ThrowsAsync <InvalidPasswordException>(async() => await crypto.Encrypt("abc"));
        }
Ejemplo n.º 6
0
        public async void Encrypt_With_Null_Password_Throws_InvalidPasswordException()
        {
            var crypto = new AesBasicCrypto_StorageOverride((byte[]?)null);

            await Assert.ThrowsAsync <InvalidPasswordException>(async() => await crypto.Encrypt("abc"));
        }