コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }