public static IDataProtectionBuilder PersistKeysToServiceFabric(this IDataProtectionBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return(builder.Use(ServiceDescriptor.Singleton <IXmlRepository>(services => new ServiceFabricXmlRepository()))); }
/// <summary> /// Sets up data protection to protect session keys with a provided certificate. /// </summary> /// <param name="builder">The <see cref="IDataProtectionBuilder"/> used to set up data protection options.</param> /// <param name="certificate">The certificate to use for session key encryption.</param> /// <returns> /// The <paramref name="builder" /> for continued configuration. /// </returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="builder" /> or <paramref name="certificate" /> is <see langword="null" />. /// </exception> /// <remarks> /// <para> /// The standard certificate encryption allows you to pass in a certificate for /// encryption, but during decryption requires the certificate to be in the /// machine certificate store. This version uses only the certificate provided /// and does not look at the certificate store. /// </para> /// </remarks> public static IDataProtectionBuilder ProtectKeysWithProvidedCertificate(this IDataProtectionBuilder builder, X509Certificate2 certificate) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (certificate == null) { throw new ArgumentNullException(nameof(certificate)); } var options = new CertificateEncryptionOptions(certificate); return(builder .Use(new ServiceDescriptor(typeof(CertificateEncryptionOptions), options)) .Use(new ServiceDescriptor(typeof(IXmlEncryptor), typeof(CertificateXmlEncryptor), ServiceLifetime.Singleton)) .Use(new ServiceDescriptor(typeof(IXmlDecryptor), typeof(CertificateXmlDecryptor), ServiceLifetime.Singleton))); }
/// <summary> /// Sets up data protection to persist session keys in Redis. /// </summary> /// <param name="builder">The <see cref="IDataProtectionBuilder"/> used to set up data protection options.</param> /// <param name="redisConnectionString">The connection string specifying the Redis instance and database for key storage.</param> /// <returns> /// The <paramref name="builder" /> for continued configuration. /// </returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="builder" /> or <paramref name="redisConnectionString" /> is <see langword="null" />. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown if <paramref name="redisConnectionString" /> is empty. /// </exception> public static IDataProtectionBuilder PersistKeysToRedis(this IDataProtectionBuilder builder, string redisConnectionString) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (redisConnectionString == null) { throw new ArgumentNullException(nameof(redisConnectionString)); } if (redisConnectionString.Length == 0) { throw new ArgumentException("Redis connection string may not be empty.", nameof(redisConnectionString)); } return(builder.Use(ServiceDescriptor.Singleton <IXmlRepository>(services => new RedisXmlRepository(redisConnectionString, services.GetRequiredService <ILogger <RedisXmlRepository> >())))); }