public CryptographicKey GetValidationKey()
 {
     if (_validationKey == null)
     {
         _validationKey = GenerateCryptographicKey(_options.ValidationKey);
     }
     return(_validationKey);
 }
 public CryptographicKey GetEncryptionKey()
 {
     if (_encryptionKey == null)
     {
         _encryptionKey = GenerateCryptographicKey(_options.DecryptionKey);
     }
     return(_encryptionKey);
 }
        private static CryptographicKey DeriveKey(CryptographicKey keyDerivationKey)
        {
            using (HMACSHA512 hmac = CryptoAlgorithms.CreateHMACSHA512(keyDerivationKey.GetKeyMaterial()))
            {
                byte[] label, context;
                GetKeyDerivationParameters(out label, out context);

                byte[] derivedKey = DeriveKeyImpl(hmac, label, context, keyDerivationKey.KeyLength);
                return(new CryptographicKey(derivedKey));
            }
        }
        private NetFXCryptoService GetNetFXCryptoService()
        {
            if (_encryptionKey == null)
            {
                _encryptionKey = DeriveKey(_masterKeyProvider.GetEncryptionKey());
            }
            if (_validationKey == null)
            {
                _validationKey = DeriveKey(_masterKeyProvider.GetValidationKey());
            }

            // and return the ICryptoService
            // (predictable IV turned on if the caller requested cacheable output)
            return(new NetFXCryptoService(_cryptoAlgorithmFactory, _encryptionKey, _validationKey));
        }
 public NetFXCryptoService(ICryptoAlgorithmFactory cryptoAlgorithmFactory, CryptographicKey encryptionKey, CryptographicKey validationKey, bool predictableIV = false)
 {
     _cryptoAlgorithmFactory = cryptoAlgorithmFactory;
     _encryptionKey          = encryptionKey;
     _validationKey          = validationKey;
     _predictableIV          = predictableIV;
 }