Credential Class
Represents a credential stored in the Windows Credential Manager.
public sealed class CredentialConstructors
| Name | Description |
|---|---|
| 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.csInitializes 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
credentialTypeCredentialType- The type of the credential.
applicationNamestring- The name that identifies the credential.
userNamestring?- The username.
secretReadOnlyMemory<byte>- The secret, as stored by Windows.
Credential.Passwordexposes it decoded as UTF-16. commentstring?- An optional comment describing the credential.
Credential(CredentialType, string, string?, string?, string?)
Credential.csInitializes a new instance of the Credential class.
public Credential(CredentialType credentialType, string applicationName, string? userName, string? password, string? comment)Parameters
credentialTypeCredentialType- The type of the credential.
applicationNamestring- The name that identifies the credential.
userNamestring?- The username.
passwordstring?- The password or secret.
commentstring?- An optional comment describing the credential.
Properties
| Name | Description |
|---|---|
| ApplicationName | Gets the name that identifies the credential. |
| Comment | Gets the comment describing the credential. |
| CredentialType | Gets the type of the credential. |
| Password | Gets the password or secret associated with the credential, decoded as UTF-16. |
| Secret | Gets the secret associated with the credential, exactly as stored by Windows. |
| UserName | Gets the username associated with the credential. |
ApplicationName
Credential.csComment
Credential.csCredentialType
Credential.csPassword
Credential.csGets the password or secret associated with the credential, decoded as UTF-16.
public string? Password { get; }Property value
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.
Secret
Credential.csGets the secret associated with the credential, exactly as stored by Windows.
public ReadOnlyMemory<byte> Secret { get; }Property value
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.
UserName
Credential.csMethods
| Name | Description |
|---|---|
| ToString() |