Oakrey.Applications.Settings.Secure 8.0.0

dotnet add package Oakrey.Applications.Settings.Secure --version 8.0.0
                    
NuGet\Install-Package Oakrey.Applications.Settings.Secure -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Applications.Settings.Secure" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.Settings.Secure" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.Settings.Secure" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Applications.Settings.Secure --version 8.0.0
                    
#r "nuget: Oakrey.Applications.Settings.Secure, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Applications.Settings.Secure@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Applications.Settings.Secure&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.Settings.Secure&version=8.0.0
                    
Install as a Cake Tool

Oakrey.Applications.Settings.Secure

Readable JSON settings support for critical application settings. It adds integrity protection, Windows-user authorization, and an audit history while keeping standard ISettingsService<T> available for regular Settings.json data.

Main features

  • Separate secure file - secured settings are stored in SecuredSettings.json; regular settings remain in Settings.json.
  • Readable JSON - secured values remain visible to users, but unnoticed external edits are detected.
  • External change detection - the whole secured settings payload and history are signed with HMACSHA256.
  • DPAPI-protected integrity key - the per-user HMAC key is encrypted at rest and legacy raw keys are migrated automatically.
  • Bounded parser - secure documents are limited to 16 MiB and JSON depth 32.
  • Authorized changes only - writes are allowed only when ISecureSettingsChangeAuthorizer approves the current Windows user.
  • Audit history - each persistent secured setting change stores the user, machine, application version, section, key, old value, and new value.
  • Explicit API - critical settings use ISecuredSettingsService<T> or SecuredSettingsBase; normal settings continue to use ISettingsService<T> and SettingsBase.

Installation

dotnet add package Oakrey.Applications.Settings.Secure

Configuration

Register the standard and secured settings services side by side:

services
    .ConfigureSettingUnderlyingServices()
    .ConfigureSecureSettingService(options =>
    {
        options.AllowedUserNames.Add(@"DOMAIN\UserName");
        options.AllowedRoles.Add(@"BUILTIN\Administrators");
    });

ConfigureSettingUnderlyingServices() registers the regular ISettingsService<T> backed by Settings.json. ConfigureSecureSettingService() registers ISecuredSettingsService<T> backed by SecuredSettings.json and does not replace the regular service.

If no user or role is configured, any authenticated Windows user running the application is allowed to change secured settings.

Example usage

Regular settings can stay unchanged:

public sealed class UiSettings(ISettingsService<UiSettings> settingsService)
    : SettingsBase(settingsService)
{
    public string Theme
    {
        get => Get<string>() ?? "Dark";
        set => Set(value);
    }
}

Critical settings opt in to the secured service:

public sealed class CalibrationSettings(ISecuredSettingsService<CalibrationSettings> settingsService)
    : SecuredSettingsBase(settingsService)
{
    public double Gain
    {
        get => Get<double>();
        set => Set(value);
    }
}

File paths

By default, DefaultSecuredSettingsPathProvider stores SecuredSettings.json in the same directory as IApplicationInfo.UserSettingsPath. Applications with a different layout can replace ISecuredSettingsPathProvider.

JSON shape

The secured settings file stays readable:

{
  "Version": 1,
  "Settings": {
    "My.Application.CalibrationSettings": {
      "Gain": {
        "Type": "System.Double",
        "Value": 1.25
      }
    }
  },
  "History": [],
  "Protection": {
    "Algorithm": "HMACSHA256",
    "KeyId": "LocalUserProfile:...",
    "Signature": "...",
    "SignedAtUtc": "2026-07-09T08:00:00+00:00"
  }
}

Manual edits to Settings or History invalidate Protection.Signature; the next load throws SecureSettingsTamperException.

Integrity key

The default key provider stores the HMAC key in the current user profile protected by Windows DPAPI. Existing 64-byte raw keys are migrated in place without changing the signed settings. The legacy SecureSettings directory name is retained for storage compatibility. Applications can replace the integrity-key provider when they need a different lifecycle.

Security note

This project protects SecuredSettings.json from unnoticed external modification and enforces application-level authorization before writes. It does not make the JSON confidential; values and audit history remain readable. DPAPI protects only the HMAC integrity key.

Product Compatible and additional computed target framework versions.
.NET net11.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 66 11/30/2026