public DataKeyProvider(
     IQueryRepository <SharedDataKey> queryRepository,
     ITransactionManager transactionManager,
     IMasterKeyProvider masterKeyProvider)
 {
     _queryRepository    = queryRepository;
     _transactionManager = transactionManager;
     _masterKeyProvider  = masterKeyProvider;
 }
 public DataKeyProvider(
     IDataKeyRepository dataKeyRepository,
     IVaultTransactionManager transactionManager,
     IMasterKeyProvider masterKeyProvider)
 {
     _dataKeyRepository  = dataKeyRepository;
     _transactionManager = transactionManager;
     _masterKeyProvider  = masterKeyProvider;
 }
Example #3
0
        // This constructor is used only for testing purposes and by the singleton provider
        // and should not otherwise be called during ASP.NET request processing.
        internal AspNetCoreCryptoServiceProvider(MachineKeyConfig machineKeyConfig = null, ICryptoAlgorithmFactory cryptoAlgorithmFactory = null, IMasterKeyProvider masterKeyProvider = null, IDataProtectorFactory dataProtectorFactory = null, KeyDerivationFunction keyDerivationFunction = null)
        {
            _machineKeyConfig       = machineKeyConfig;
            _cryptoAlgorithmFactory = cryptoAlgorithmFactory;
            _masterKeyProvider      = masterKeyProvider;
            _dataProtectorFactory   = dataProtectorFactory;
            _keyDerivationFunction  = keyDerivationFunction;

            // The DataProtectorCryptoService is active if specified as such in config
            _isDataProtectorEnabled = (machineKeyConfig != null && !String.IsNullOrWhiteSpace(machineKeyConfig.DataProtectorType));
        }
        // This constructor is used only for testing purposes and by the singleton provider
        // and should not otherwise be called during ASP.NET request processing.
        internal AspNetCryptoServiceProvider(MachineKeySection machineKeySection = null, ICryptoAlgorithmFactory cryptoAlgorithmFactory = null, IMasterKeyProvider masterKeyProvider = null, IDataProtectorFactory dataProtectorFactory = null, KeyDerivationFunction keyDerivationFunction = null) {
            _machineKeySection = machineKeySection;
            _cryptoAlgorithmFactory = cryptoAlgorithmFactory;
            _masterKeyProvider = masterKeyProvider;
            _dataProtectorFactory = dataProtectorFactory;
            _keyDerivationFunction = keyDerivationFunction;

            // This CryptoServiceProvider is active if specified as such in the <system.web/machineKey> section
            IsDefaultProvider = (machineKeySection != null && machineKeySection.CompatibilityMode >= MachineKeyCompatibilityMode.Framework45);

            // The DataProtectorCryptoService is active if specified as such in config
            _isDataProtectorEnabled = (machineKeySection != null && !String.IsNullOrWhiteSpace(machineKeySection.DataProtectorType));
        }
Example #5
0
        // This constructor is used only for testing purposes and by the singleton provider
        // and should not otherwise be called during ASP.NET request processing.
        internal AspNetCryptoServiceProvider(MachineKeySection machineKeySection = null, ICryptoAlgorithmFactory cryptoAlgorithmFactory = null, IMasterKeyProvider masterKeyProvider = null, IDataProtectorFactory dataProtectorFactory = null, KeyDerivationFunction keyDerivationFunction = null)
        {
            _machineKeySection      = machineKeySection;
            _cryptoAlgorithmFactory = cryptoAlgorithmFactory;
            _masterKeyProvider      = masterKeyProvider;
            _dataProtectorFactory   = dataProtectorFactory;
            _keyDerivationFunction  = keyDerivationFunction;

            // This CryptoServiceProvider is active if specified as such in the <system.web/machineKey> section
            IsDefaultProvider = (machineKeySection != null && machineKeySection.CompatibilityMode >= MachineKeyCompatibilityMode.Framework45);

            // The DataProtectorCryptoService is active if specified as such in config
            _isDataProtectorEnabled = (machineKeySection != null && !String.IsNullOrWhiteSpace(machineKeySection.DataProtectorType));
        }
Example #6
0
        public CryptographicKey GetDerivedValidationKey(IMasterKeyProvider masterKeyProvider, KeyDerivationFunction keyDerivationFunction)
        {
            CryptographicKey cryptographicKey = this.DerivedValidationKey;

            if (cryptographicKey == null)
            {
                CryptographicKey validationKey = masterKeyProvider.GetValidationKey();
                cryptographicKey = keyDerivationFunction(validationKey, this);
                if (this.SaveDerivedKeys)
                {
                    this.DerivedValidationKey = cryptographicKey;
                }
            }
            return(cryptographicKey);
        }
Example #7
0
        public CryptographicKey GetDerivedValidationKey(IMasterKeyProvider masterKeyProvider, KeyDerivationFunction keyDerivationFunction)
        {
            // has a key already been stored?
            CryptographicKey actualDerivedKey = DerivedValidationKey;

            if (actualDerivedKey == null)
            {
                CryptographicKey masterKey = masterKeyProvider.GetValidationKey();
                actualDerivedKey = keyDerivationFunction(masterKey, this);

                // only save the key back to storage if this Purpose is configured to do so
                if (SaveDerivedKeys)
                {
                    DerivedValidationKey = actualDerivedKey;
                }
            }

            return(actualDerivedKey);
        }
        private byte[] _encryptionIV = null;//SORCE_CHANGED added encryption IV to re-ecrypt the data

        // This constructor is used only for testing purposes and by the singleton provider
        // and should not otherwise be called during ASP.NET request processing.
        internal AspNetCryptoServiceProvider(string strValidationKey, string strValAlgo, string strDecryptionKey, string strDecAlgo)
        {
            MachineKeySection machineKeySection = new MachineKeySection();

            machineKeySection.DecryptionKey       = strDecryptionKey;
            machineKeySection.Decryption          = strDecAlgo;
            machineKeySection.ValidationKey       = strValidationKey;
            machineKeySection.ValidationAlgorithm = strValAlgo;

            _machineKeySection      = machineKeySection;
            _cryptoAlgorithmFactory = new MachineKeyCryptoAlgorithmFactory(machineKeySection);
            _masterKeyProvider      = new MachineKeyMasterKeyProvider(machineKeySection);
            _dataProtectorFactory   = new MachineKeyDataProtectorFactory(machineKeySection);
            _keyDerivationFunction  = SP800_108.DeriveKey;

            // This CryptoServiceProvider is active if specified as such in the <system.web/machineKey> section
            IsDefaultProvider = (machineKeySection != null && machineKeySection.CompatibilityMode >= MachineKeyCompatibilityMode.Framework45);

            // The DataProtectorCryptoService is active if specified as such in config
            _isDataProtectorEnabled = (machineKeySection != null && !String.IsNullOrWhiteSpace(machineKeySection.DataProtectorType));
        }
Example #9
0
        public CryptographicKey GetDerivedValidationKey(IMasterKeyProvider masterKeyProvider, KeyDerivationFunction keyDerivationFunction) {
            // has a key already been stored?
            CryptographicKey actualDerivedKey = DerivedValidationKey;
            if (actualDerivedKey == null) {
                CryptographicKey masterKey = masterKeyProvider.GetValidationKey();
                actualDerivedKey = keyDerivationFunction(masterKey, this);

                // only save the key back to storage if this Purpose is configured to do so
                if (SaveDerivedKeys) {
                    DerivedValidationKey = actualDerivedKey;
                }
            }

            return actualDerivedKey;
        }
 private AspNetCryptoServiceProvider(ICryptoAlgorithmFactory cryptoAlgorithmFactory, IMasterKeyProvider masterKeyProvider)
 {
     _cryptoAlgorithmFactory = cryptoAlgorithmFactory;
     _masterKeyProvider      = masterKeyProvider;
 }
 public Decryptor(string encryptionKey, string validationKey, ValidationAlgorithm algorithm)
 {
     _masterKeyProvider      = new DefaultMasterKeyProvider(encryptionKey, validationKey);
     _cryptoAlgorithmFactory = new DefaultCryptoAlgorithmFactory(algorithm);
 }