Inheritance: WebApplications.Utilities.Configuration.ConfigurationElement
        private AESCryptographer([NotNull] ProviderElement provider, IEnumerable<Key> keys = null)
        {
            _provider = provider;

            if (keys == null)
                return;

            _aesEncryptionKeys.AddRange(keys);
            // ReSharper disable PossibleNullReferenceException
            _aesEncryptionKeys.Sort((a, b) => b.Expiry.CompareTo(a.Expiry));
            // ReSharper restore PossibleNullReferenceException
        }
Beispiel #2
0
        public CryptographyProvider GetOrAddProvider(
            [NotNull] string providerId,
            [NotNull] Func <CryptographyProvider> addFunc)
        {
            if (string.IsNullOrWhiteSpace(providerId))
            {
                throw new ArgumentException(
                          Resources.CryptographyConfiguration_GetOrAddProvider_Invalid_Provider_ID,
                          nameof(providerId));
            }

            // ReSharper disable ExceptionNotDocumented
            ProviderElement      providerElement = Providers[providerId];
            CryptographyProvider provider;

            if (providerElement != null)
            {
                // Enable the provider if disabled.
                if (!providerElement.IsEnabled)
                {
                    providerElement.IsEnabled = true;
                }

                // Try to get the provider
                provider = providerElement.GetProvider();
                if (provider != null)
                {
                    // Set the provider's ID so it knows it came from the configuration.
                    provider.Id = providerId;
                    return(provider);
                }
            }

            // Create a new provider
            provider = addFunc();
            if (provider == null)
            {
                throw new CryptographicException(
                          Resources.CryptographyConfiguration_GetOrAddProvider_Add_Returned_Null);
            }

            // Set the provider's ID so it knows it came from the configuration.
            provider.Id = providerId;

            if (providerElement == null)
            {
                providerElement = new ProviderElement
                {
                    Id            = providerId,
                    Name          = provider.Name,
                    Configuration = provider.Configuration,
                    IsEnabled     = true
                };
                Providers.Add(providerElement);
            }
            else
            {
                providerElement.Id            = providerId;
                providerElement.Name          = provider.Name;
                providerElement.Configuration = provider.Configuration;
                providerElement.IsEnabled     = true;
            }

            // Save this configuration
            Save();

            // Return the provider
            return(provider);
        }