### [Apq\.Cfg\.Crypto\.DataProtection](Apq.Cfg.Crypto.DataProtection.md 'Apq\.Cfg\.Crypto\.DataProtection').[CfgBuilderExtensions](Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.md 'Apq\.Cfg\.Crypto\.DataProtection\.CfgBuilderExtensions') ## CfgBuilderExtensions\.AddDataProtectionEncryption Method | Overloads | | | :--- | :--- | | [AddDataProtectionEncryption\(this CfgBuilder, IDataProtectionProvider, string, Action<EncryptionOptions>\)](Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption.md#Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption(thisApq.Cfg.CfgBuilder,Microsoft.AspNetCore.DataProtection.IDataProtectionProvider,string,System.Action_Apq.Cfg.Crypto.EncryptionOptions_) 'Apq\.Cfg\.Crypto\.DataProtection\.CfgBuilderExtensions\.AddDataProtectionEncryption\(this Apq\.Cfg\.CfgBuilder, Microsoft\.AspNetCore\.DataProtection\.IDataProtectionProvider, string, System\.Action\\)') | 添加 Data Protection 加密支持 | | [AddDataProtectionEncryption\(this CfgBuilder, string, string, Action<EncryptionOptions>\)](Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption.md#Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption(thisApq.Cfg.CfgBuilder,string,string,System.Action_Apq.Cfg.Crypto.EncryptionOptions_) 'Apq\.Cfg\.Crypto\.DataProtection\.CfgBuilderExtensions\.AddDataProtectionEncryption\(this Apq\.Cfg\.CfgBuilder, string, string, System\.Action\\)') | 添加 Data Protection 加密支持(使用默认提供者) | | [AddDataProtectionEncryption\(this CfgBuilder, DirectoryInfo, string, string, Action<EncryptionOptions>\)](Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption.md#Apq.Cfg.Crypto.DataProtection.CfgBuilderExtensions.AddDataProtectionEncryption(thisApq.Cfg.CfgBuilder,System.IO.DirectoryInfo,string,string,System.Action_Apq.Cfg.Crypto.EncryptionOptions_) 'Apq\.Cfg\.Crypto\.DataProtection\.CfgBuilderExtensions\.AddDataProtectionEncryption\(this Apq\.Cfg\.CfgBuilder, System\.IO\.DirectoryInfo, string, string, System\.Action\\)') | 添加 Data Protection 加密支持(使用指定目录存储密钥) | ## CfgBuilderExtensions\.AddDataProtectionEncryption\(this CfgBuilder, IDataProtectionProvider, string, Action\\) Method 添加 Data Protection 加密支持 ```csharp public static Apq.Cfg.CfgBuilder AddDataProtectionEncryption(this Apq.Cfg.CfgBuilder builder, Microsoft.AspNetCore.DataProtection.IDataProtectionProvider provider, string purpose="Apq.Cfg", System.Action? configure=null); ``` #### Parameters `builder` [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器 `provider` [Microsoft\.AspNetCore\.DataProtection\.IDataProtectionProvider](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.dataprotection.idataprotectionprovider 'Microsoft\.AspNetCore\.DataProtection\.IDataProtectionProvider') Data Protection 提供者 `purpose` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') 保护目的,用于隔离不同用途的加密数据 `configure` [System\.Action<](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1')[Apq\.Cfg\.Crypto\.EncryptionOptions](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.crypto.encryptionoptions 'Apq\.Cfg\.Crypto\.EncryptionOptions')[>](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1') 加密选项配置委托 #### Returns [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器实例,支持链式调用 ### Example ```csharp var dataProtectionProvider = DataProtectionProvider.Create("MyApp"); var cfg = new CfgBuilder() .AddJson("config.json", level: 0) .AddDataProtectionEncryption(dataProtectionProvider) .Build(); ``` ## CfgBuilderExtensions\.AddDataProtectionEncryption\(this CfgBuilder, string, string, Action\\) Method 添加 Data Protection 加密支持(使用默认提供者) ```csharp public static Apq.Cfg.CfgBuilder AddDataProtectionEncryption(this Apq.Cfg.CfgBuilder builder, string applicationName, string purpose="Apq.Cfg", System.Action? configure=null); ``` #### Parameters `builder` [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器 `applicationName` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') 应用程序名称,用于密钥隔离 `purpose` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') 保护目的 `configure` [System\.Action<](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1')[Apq\.Cfg\.Crypto\.EncryptionOptions](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.crypto.encryptionoptions 'Apq\.Cfg\.Crypto\.EncryptionOptions')[>](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1') 加密选项配置委托 #### Returns [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器实例,支持链式调用 ### Example ```csharp var cfg = new CfgBuilder() .AddJson("config.json", level: 0) .AddDataProtectionEncryption("MyApp") .Build(); ``` ## CfgBuilderExtensions\.AddDataProtectionEncryption\(this CfgBuilder, DirectoryInfo, string, string, Action\\) Method 添加 Data Protection 加密支持(使用指定目录存储密钥) ```csharp public static Apq.Cfg.CfgBuilder AddDataProtectionEncryption(this Apq.Cfg.CfgBuilder builder, System.IO.DirectoryInfo keyDirectory, string applicationName, string purpose="Apq.Cfg", System.Action? configure=null); ``` #### Parameters `builder` [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器 `keyDirectory` [System\.IO\.DirectoryInfo](https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo 'System\.IO\.DirectoryInfo') 密钥存储目录 `applicationName` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') 应用程序名称 `purpose` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') 保护目的 `configure` [System\.Action<](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1')[Apq\.Cfg\.Crypto\.EncryptionOptions](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.crypto.encryptionoptions 'Apq\.Cfg\.Crypto\.EncryptionOptions')[>](https://learn.microsoft.com/en-us/dotnet/api/system.action-1 'System\.Action\`1') 加密选项配置委托 #### Returns [Apq\.Cfg\.CfgBuilder](https://learn.microsoft.com/en-us/dotnet/api/apq.cfg.cfgbuilder 'Apq\.Cfg\.CfgBuilder') 配置构建器实例,支持链式调用 ### Example ```csharp var cfg = new CfgBuilder() .AddJson("config.json", level: 0) .AddDataProtectionEncryption(new DirectoryInfo("/keys"), "MyApp") .Build(); ```