public static Encryptor CreateEncryptorWithGivenSalt(
            [NotNull] this SymmetricAlgorithm algorithm,
            [NotNull] string secretKey,
            [NotNull] string salt,
            ByteArrayStringEncoding saltEncoding = ConvertByteArray.DefaultStringEncoding,
            EncryptionOptions options            = DefaultOptions)
        {
            Contract.Requires <ArgumentNullException>(algorithm != null);
            Contract.Requires <ArgumentNullException>(secretKey != null);
            Contract.Requires <ArgumentNullException>(salt != null);

            return(algorithm.CreateEncryptorWithGivenSalt(secretKey, salt.ToByteArray(saltEncoding), options));
        }
        public static Encryptor CreateEncryptorWithGivenSalt(
            [NotNull] this SymmetricAlgorithm algorithm,
            [NotNull] string secretKey,
            [NotNull] byte[] salt,
            EncryptionOptions options = DefaultOptions)
        {
            Contract.Requires <ArgumentNullException>(algorithm != null);
            Contract.Requires <ArgumentNullException>(secretKey != null);
            Contract.Requires <ArgumentNullException>(salt != null);

            return(algorithm.CreateEncryptorWithGivenSalt(
                       DeriveEncryptionKeyFromPasswordAndSalt(secretKey, algorithm.KeySize, salt),
                       salt,
                       options));
        }
        public static EncryptorWithChecksum CreateEncryptorWithGivenSalt(
            [NotNull] this SymmetricAlgorithm algorithm,
            [NotNull] KeyedHashAlgorithm checksumHasher,
            [NotNull] string password,
            [NotNull] string salt,
            ByteArrayStringEncoding saltEncoding = ConvertByteArray.DefaultStringEncoding,
            EncryptionOptions options            = DefaultOptions)
        {
            Contract.Requires <ArgumentNullException>(algorithm != null);
            Contract.Requires <ArgumentNullException>(checksumHasher != null);
            Contract.Requires <ArgumentNullException>(password != null);
            Contract.Requires <ArgumentNullException>(salt != null);

            return(algorithm.CreateEncryptorWithGivenSalt(
                       checksumHasher, password, salt.ToByteArray(saltEncoding), options));
        }
        public static Encryptor CreateEncryptor(
            [NotNull] this SymmetricAlgorithm algorithm,
            [NotNull] string secretKey,
            out byte[] randomSalt,
            EncryptionOptions options = DefaultOptions)
        {
            Contract.Requires <ArgumentNullException>(algorithm != null);
            Contract.Requires <ArgumentNullException>(secretKey != null);

            // In this case, use the more robustly random
            // key derivation algorithm to create the salt,
            // instead of the SymmetricAlgorithm.
            return(algorithm.CreateEncryptorWithGivenSalt(
                       DeriveEncryptionKeyAndSaltFromPassword(secretKey, algorithm.KeySize, algorithm.BlockSize, out randomSalt),
                       randomSalt,
                       options));
        }
        public static EncryptorWithChecksum CreateEncryptorWithGivenSalt(
            [NotNull] this SymmetricAlgorithm algorithm,
            [NotNull] KeyedHashAlgorithm checksumHasher,
            [NotNull] string password,
            [NotNull] byte[] salt,
            EncryptionOptions options = DefaultOptions)
        {
            Contract.Requires <ArgumentNullException>(algorithm != null);
            Contract.Requires <ArgumentNullException>(checksumHasher != null);
            Contract.Requires <ArgumentNullException>(password != null);
            Contract.Requires <ArgumentNullException>(salt != null);

            return(algorithm.CreateEncryptorWithGivenSalt(
                       checksumHasher,
                       DeriveEncryptionKeyFromPasswordAndSalt(password, algorithm.KeySize, salt),
                       salt,
                       options));
        }