Credential Class

Represents a credential stored in the Windows Credential Manager.

public sealed class Credential

Constructors

NameDescription
Credential(CredentialType, string, string?, ReadOnlyMemory<byte>, string?)Initializes a new instance of the Credential class from a raw secret.
Credential(CredentialType, string, string?, string?, string?)Initializes a new instance of the Credential class.

Credential overloads

Credential(CredentialType, string, string?, ReadOnlyMemory<byte>, string?)

Credential.cs

Initializes a new instance of the Credential class from a raw secret.

public Credential(CredentialType credentialType, string applicationName, string? userName, ReadOnlyMemory<byte> secret, string? comment)
Parameters
credentialType CredentialType
The type of the credential.
applicationName string
The name that identifies the credential.
userName string?
The username.
secret ReadOnlyMemory<byte>
The secret, as stored by Windows. Credential.Password exposes it decoded as UTF-16.
comment string?
An optional comment describing the credential.

Credential(CredentialType, string, string?, string?, string?)

Credential.cs

Initializes a new instance of the Credential class.

public Credential(CredentialType credentialType, string applicationName, string? userName, string? password, string? comment)
Parameters
credentialType CredentialType
The type of the credential.
applicationName string
The name that identifies the credential.
userName string?
The username.
password string?
The password or secret.
comment string?
An optional comment describing the credential.

Properties

NameDescription
ApplicationNameGets the name that identifies the credential.
CommentGets the comment describing the credential.
CredentialTypeGets the type of the credential.
PasswordGets the password or secret associated with the credential, decoded as UTF-16.
SecretGets the secret associated with the credential, exactly as stored by Windows.
UserNameGets the username associated with the credential.

ApplicationName

Credential.cs

Gets the name that identifies the credential.

public string ApplicationName { get; }

Property value

string

Gets the comment describing the credential.

public string? Comment { get; }

Property value

string?

CredentialType

Credential.cs

Gets the type of the credential.

public CredentialType CredentialType { get; }

Property value

CredentialType

Gets the password or secret associated with the credential, decoded as UTF-16.

public string? Password { get; }

Property value

string?

Remarks

Decoding is lossy when the credential holds arbitrary binary data: a trailing odd byte is dropped, and bytes that do not form valid UTF-16 do not survive being encoded again. Use Credential.Secret to get the bytes exactly as Windows stored them.

Gets the secret associated with the credential, exactly as stored by Windows.

public ReadOnlyMemory<byte> Secret { get; }

Property value

ReadOnlyMemory<byte>

Remarks

For CredentialType.Generic credentials the layout of the blob is defined by the application that wrote it, so it may hold arbitrary bytes rather than text. The value is empty when the credential carries no secret.

Gets the username associated with the credential.

public string? UserName { get; }

Property value

string?

Methods

NameDescription
ToString()

ToString()

Credential.cs
public override string ToString()

Returns

string

No documentation is available.