コード例 #1
0
        public static IPassawordBuilder AddPassaword(this IServiceCollection services, Action <PassawordOptions> options = null)
        {
            var context = new PassawordContext();

            var o = new PassawordOptions();

            options?.Invoke(o);

            context.OnDecryptionFailed    = o.OnDecryptionFailed;
            context.OnSecretDecrypted     = o.OnSecretDecrypted;
            context.OnSecretEncrypted     = o.OnSecretEncrypted;
            context.OnPreValidationFailed = o.OnPreValidationFailed;

            services.AddSingleton <PassawordContext>(context);
            services.AddTransient <ISecretValidator, DefaultSecretValidator>();
            services.AddTransient <IKeyGenerator, DefaultKeyGenerator>();
            services.AddTransient <ISymmetricEncryptor, Aes256Encryptor>();
            services.AddTransient <Aes256Encryptor, Aes256Encryptor>();
            services.AddTransient <SecretEncryptionContext, SecretEncryptionContext>();
            services.AddTransient <SecretDecryptionContext, SecretDecryptionContext>();
            services.AddTransient <EncryptionEventArgs, EncryptionEventArgs>();
            services.AddTransient <DecryptionEventArgs, DecryptionEventArgs>();
            services.AddTransient <DecryptionFailedEventArgs, DecryptionFailedEventArgs>();
            services.AddTransient <ISecretContextService, DefaultSecretContextService>();
            services.AddTransient <IMessageContentStore, DefaultMessageContentStore>();

            return(new PassawordBuilder()
            {
                Services = services
            });
        }
コード例 #2
0
 public DefaultSecretValidator(IServiceProvider serviceProvider, PassawordContext context)
 {
     _serviceProvider = serviceProvider;
     _context         = context;
 }