Skip to content

Instantly share code, notes, and snippets.

@swaters86
Created February 20, 2026 13:53
Show Gist options
  • Select an option

  • Save swaters86/d920a54a266f58cfca6e6e429d636519 to your computer and use it in GitHub Desktop.

Select an option

Save swaters86/d920a54a266f58cfca6e6e429d636519 to your computer and use it in GitHub Desktop.
using Microsoft.Win32;
public static class SecretRegistry
{
private const string KeyPath = @"SOFTWARE\YourCompany\Connector\Secrets";
public static void SaveClientSecret(string secretPlaintext)
{
string protectedBase64 = DpapiSecretStore.ProtectToBase64(secretPlaintext);
using (var key = Registry.LocalMachine.CreateSubKey(KeyPath, writable: true))
{
key.SetValue("CognitoClientSecret", protectedBase64, RegistryValueKind.String);
}
}
public static string LoadClientSecret()
{
using (var key = Registry.LocalMachine.OpenSubKey(KeyPath, writable: false))
{
var protectedBase64 = key?.GetValue("CognitoClientSecret") as string;
return DpapiSecretStore.UnprotectFromBase64(protectedBase64);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment