Table of Contents

Class ProtectedDataHelper

Namespace
SunamoSecurity
Assembly
SunamoSecurity.dll

Provides methods to encrypt and decrypt strings using the Windows Data Protection API (DPAPI).

public static class ProtectedDataHelper
Inheritance
ProtectedDataHelper
Inherited Members

Methods

DecryptString(string, string, DataProtectionScope)

Decrypts a Base64-encoded encrypted string using DPAPI with the specified salt.

public static SecureString DecryptString(string salt, string encryptedText, DataProtectionScope dataProtectionScope = DataProtectionScope.CurrentUser)

Parameters

salt string

The salt used as additional entropy for decryption.

encryptedText string

The Base64-encoded encrypted string to decrypt.

dataProtectionScope DataProtectionScope

The scope of data protection (current user or local machine).

Returns

SecureString

The decrypted value as a SecureString. Returns an empty SecureString if decryption fails.

EncryptString(string, SecureString, DataProtectionScope)

Encrypts a SecureString using DPAPI with the specified salt.

public static string? EncryptString(string salt, SecureString secureString, DataProtectionScope dataProtectionScope = DataProtectionScope.CurrentUser)

Parameters

salt string

The salt used as additional entropy for encryption.

secureString SecureString

The secure string to encrypt.

dataProtectionScope DataProtectionScope

The scope of data protection (current user or local machine).

Returns

string

The encrypted string as a Base64-encoded value, or null if the input is null.