Show / Hide Table of Contents

AddCredential Method

AddCredential(Credential)

Adds a new credential or overwrites the existing one on the YubiKey.

C#
public void AddCredential(Credential credential)

Parameters

Type Name Description
Credential credential

The Credential to add to the YubiKey.

Exceptions

Type Condition
ArgumentNullException

Provided credential is null.

InvalidOperationException

There is no KeyCollector loaded if the authentication is required, some credential properties are not supported on this YubiKey, or the PutCommand failed.

SecurityException

Unable to verify password either because KeyCollector was canceled by the user or an incorrect password was provided if authentication is required.

AddCredential(string?, string, CredentialType, CredentialPeriod)

Adds a new credential or overwrites the existing one on the YubiKey with default parameters.

C#
public Credential AddCredential(string? issuer, string account, CredentialType type = CredentialType.Totp, CredentialPeriod period = CredentialPeriod.Period30)

Parameters

Type Name Description
string issuer

The issuer is an optional string indicating the provider or service.

string account

The account name that usually is the user's email address.

CredentialType type

Indicates the CredentialType of the credential as either HOTP or TOTP. The default value is TOTP.

CredentialPeriod period

Indicates the CredentialPeriod of the credential in seconds for TOTP code. It can only be 15, 30, or 60 seconds. For HOTP should be set to zero (Undefined). The default value is 30.

Returns

Credential

The Credential that was created and added to the YubiKey.

Exceptions

Type Condition
InvalidOperationException

There is no KeyCollector loaded if the authentication is required, the PutCommand failed, or the provided account, type, or period is invalid.

SecurityException

Unable to verify password either because KeyCollector was canceled by the user or an incorrect password was provided if authentication is required.

Remarks

If type and period properties are not modified, this will add a TOTP credential with default parameters like: Type - TOTP, Period - 30 seconds, Algorithm - SHA-1, Digits - 6, No secret, No touch.

AddCredential(string)

Adds a credential from the string that received from the QR reader or manually from the server.

C#
public Credential AddCredential(string stringFromURI)

Parameters

Type Name Description
string stringFromURI

The string that received from the QR reader or manually from the server.

Returns

Credential

The Credential that was created and added to the YubiKey.

Exceptions

Type Condition
ArgumentNullException

Provided string is null, empty, or consists only of white-space characters.

InvalidOperationException

There is no KeyCollector loaded if the authentication is required, some credential properties are not supported on this YubiKey, the PutCommand failed, or the URI string is invalid or it contains invalid elements.

SecurityException

Unable to verify password either because KeyCollector was canceled by the user or an incorrect password was provided if authentication is required.

Remarks

This method parses an 'otpauth://' Uri string that received from the QR reader or manually from the server, as specified by https://github.com/google/google-authenticator/wiki/Key-Uri-Format

In this article
Back to top Generated by DocFX