Ejemplo n.º 1
0
        public IEncryptionService Create(IProcessExecutionContext executionContext, bool disableCache = false)
        {
            bool useCache = !disableCache && executionContext.Cache != null;

            if (useCache && executionContext.Cache.Exists(CACHE_KEY))
            {
                return(executionContext.Cache.Get <IEncryptionService>(CACHE_KEY));
            }

            var settings = SettingsFactory.Create(executionContext);

            var secretProvider = SecretProviderFactory.Create(executionContext, disableCache);

            var encryptionKey = secretProvider.GetValue <string>(settings.EncryptionKeyName)
                                ?? throw new Exception("Missing Secret for encryption key.");

            var encryptor = new DefaultEncryptor(encryptionKey);

            var cacheTimeout = settings.CacheTimeout;

            if (useCache && cacheTimeout.HasValue)
            {
                executionContext.Cache.Add <IEncryptionService>(CACHE_KEY, encryptor, cacheTimeout.Value);
            }

            return(encryptor);
        }
        public IEncryptionService Create(IProcessExecutionContext executionContext, bool disableCache = false)
        {
            bool useCache = !disableCache && executionContext.Cache != null;

            if (useCache && executionContext.Cache.Exists(CACHE_KEY))
            {
                return(executionContext.Cache.Get <IEncryptionService>(CACHE_KEY));
            }

            var settings = SettingsFactory.Create(executionContext);

            var encryptor = new DefaultEncryptor();

            var cacheTimeout = settings.CacheTimeout;

            if (useCache && cacheTimeout.HasValue)
            {
                executionContext.Cache.Add <IEncryptionService>(CACHE_KEY, encryptor, cacheTimeout.Value);
            }

            return(encryptor);
        }