SensitiveData Class
Provides factory methods for creating SensitiveData<T> instances.
public static class SensitiveDataExample
// Create sensitive data from a string
using var secret = SensitiveData.Create("my-password");
// Reveal the data when needed
string password = secret.RevealToString();
Assert.Equal("my-password", password);
// Create sensitive data from a byte array
byte[] key = [1, 2, 3, 4, 5];
using var sensitiveKey = SensitiveData.Create(key);
byte[] revealedKey = sensitiveKey.RevealToArray();
Assert.Equal(key, revealedKey);Methods
| Name | Description |
|---|---|
| Create(string) | Creates an instance of SensitiveData<T> from a string. |
| Create<T>(ReadOnlySpan<T>) | Creates an instance of SensitiveData<T> from a read-only span. |
| Create<T>(T[]) | Creates an instance of SensitiveData<T> from an array. |
| RevealToString(SensitiveData<char>) | Reveals the contents of a SensitiveData<T> instance as a string. |
Create overloads
Create(string)
SensitiveData.csCreates an instance of SensitiveData<T> from a string.
public static SensitiveData<char> Create(string value)Parameters
valuestring- The sensitive string data to protect.
Returns
SensitiveData<char> A new SensitiveData<T> instance containing the string contents.
Create<T>(ReadOnlySpan<T>)
SensitiveData.csCreates an instance of SensitiveData<T> from a read-only span.
public static SensitiveData<T> Create<T>(ReadOnlySpan<T> buffer) where T : unmanagedType parameters
T- The unmanaged type of elements in the buffer.
Parameters
bufferReadOnlySpan<T>- The read-only span containing sensitive data to protect.
Returns
SensitiveData<T> A new SensitiveData<T> instance containing a copy of the buffer contents.
Create<T>(T[])
SensitiveData.csCreates an instance of SensitiveData<T> from an array.
public static SensitiveData<T> Create<T>(T[] buffer) where T : unmanagedType parameters
T- The unmanaged type of elements in the buffer.
Parameters
bufferT[]- The buffer containing sensitive data to protect.
Returns
SensitiveData<T> A new SensitiveData<T> instance containing a copy of the buffer contents.
RevealToString(SensitiveData<char>)
SensitiveData.csReveals the contents of a SensitiveData<T> instance as a string.
public static string RevealToString(this SensitiveData<char> secret)Parameters
secretSensitiveData<char>- The sensitive data to reveal.
Returns
string A string containing the revealed sensitive data.
Exceptions
ObjectDisposedException- The instance has already been disposed.