private async Task Then_data_is_correctly_decrypted()
        {
            var decryptTask = DecryptAsync(_encryptedData);
            var controlTask = _algorithm.DecryptAsync(_encryptedData);

            var decrypted = await decryptTask;
            var control   = await controlTask;

            Assert.NotNull(decrypted);
            // NOTE: Cannot use xunit's Assert.Equal here because for some reason it is glacially slow with large data sets.
            Assert.True(SequencesAreEqual(control, decrypted), "Decrypted sequence does not match the control sequence");
        }
Esempio n. 2
0
        /// <summary>
        /// Decrypts a string that was encrypted using the same password, salt and <see cref="SymmetricAlgorithm"/> that created it
        /// </summary>
        /// <param name="algorithm">The SymmetricAlgorithm to encrypt with</param>
        /// <param name="text">The text that you want to decrypt</param>
        /// <param name="encryptionKey">The password that is used with the salt to encrypt/decrypt the text</param>
        /// <param name="salt">A value to make the text being encrypted unique to a same text being encrypted elsewhere (basically a prefix added to the text prior to encryption). A salt should be unique to each stored encrypted value and saved elsewhere.</param>
        /// <param name="iterations">Is the number of times the encryption is performed</param>
        public static Task <string> DecryptAsync(this SymmetricAlgorithm algorithm, string text, string encryptionKey, string salt, int iterations = DEFAULT_ITERATIONS)
        {
            Assert.NotNullOrEmpty(salt, nameof(salt));

            return(algorithm.DecryptAsync(text, encryptionKey, Encoding.Unicode.GetBytes(salt), iterations));
        }