Browse Source

Added `Encrypting Setting Values in the Application Configuration`section.

Resolve #21900
pull/21933/head
maliming 2 years ago
parent
commit
0c2f6176b1
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 33
      docs/en/framework/infrastructure/settings.md

33
docs/en/framework/infrastructure/settings.md

@ -160,6 +160,39 @@ Setting values should be configured under the `Settings` section as like in this
> `IConfiguration` is an .NET Core service and it can read values not only from the `appsettings.json`, but also from the environment, user secrets... etc. See [Microsoft's documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) for more.
#### Encrypting Setting Values in the Application Configuration
You have to use the `ISettingEncryptionService` to encrypt the setting values when the `IsEncrypted` property of a setting definition is set to `true`, which means that the setting value should be encrypted in the `appsettings.json`.
Example of injecting the `ISettingEncryptionService` into a class and encrypting the plain text:
````csharp
public class MyService
{
private readonly ISettingEncryptionService _encryptionService;
public MyService(ISettingEncryptionService encryptionService)
{
_encryptionService = encryptionService;
}
public void EncryptValue(string plainText)
{
var ciphertext = _encryptionService.Encrypt(plainText);
}
}
````
Then, Replace `ENCRYPTED_VALUE_HERE` with the ciphertext generated by `ISettingEncryptionService.Encrypt` method.
````json
{
"Settings": {
"MySetting": "ENCRYPTED_VALUE_HERE"
}
}
````
### Custom Setting Value Providers
If you need to extend the setting system, you can define a class derived from the `SettingValueProvider` class. Example:

Loading…
Cancel
Save