<configuration>
<system.web>
<machineKey decryptionKey="" validationKey="" />
</system.web>
</configuration>
IDataProtectionProvider dataProtectionProvider = ...;
IDataProtector dataProtector = dataProtectionProvider.CreateProtector("Demo.WebApp");
var encryptedString = dataProtector.Protect(someString);
IDataProtectionProvider dataProtectionProvider = ...;
IDataProtector dataProtector = dataProtectionProvider.CreateProtector("Demo.WebApp", "v1");
var encryptedString = dataProtector.Protect(someString);
public sealed class PurposeStringConstants
{
public string ConferenceIdQueryString => "ConferenceIdQueryString";
}
public void ConfigureServices(ISErviceCollection services)
{
services.AddMvc();
services.AddDataProtection(); // setup with fluent interface as needed
services.AddSingleton<PurposeStringConstants>();
}
public sealed class ConferenceRepository
{
private IDataProtector Protector { get; }
private IList EncryptedConferences { get; } = new List<EncryptedConference>();
public ConferenceRepository(
IDataProtectionProvider dataProtectionProvider,
PurposeStringConstants purposeStringConstants)
{
Protector = protectionProvider.CreateProtector(purposeStringConstants.ConferenceIdQueryString);
}
public void Add(Conference conference)
{
var encryptedConference = new EncryptedConference
{
Name = protector.Protect(model.Name.ToString());
}
encryptedConferences.Add(encryptedConference);
}
// ...
}
var timeLimitedDataProtector = protector.ToTimeLimitedDataProtector();
timeLimitedDataProtector.Protect(someString, dateTime);
var configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
.Build();
var connectionString = configuration["DefaultConnection"];
dotnet user-secrets set databasepassword secret
var configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddUserSecrets();
.Build();
var password = configuration["databasepassword"];