Package com.yubico.yubikit.oath
Class CredentialData
java.lang.Object
com.yubico.yubikit.oath.CredentialData
- All Implemented Interfaces:
Serializable
Data object holding all required information to add a new
Credential
to a YubiKey.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default number of digits for calculatedCode
s.static final int
The default time period for TOTP Credentials. -
Constructor Summary
ConstructorsConstructorDescriptionCredentialData
(String accountName, OathType oathType, HashAlgorithm hashAlgorithm, byte[] secret, int digits, int period, int counter, String issuer) Constructs a new instance from the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the name of the credential.int
Returns the initial counter value for a HOTP credential.int
Returns the number of digits inCode
s calculated from the credential.Returns the hash algorithm used by the credential.byte[]
getId()
Returns the credentials ID, as used to identify it on a YubiKey.Returns the name of the credential issuer.Returns the OATH type (HOTP or TOTP) of the credential.int
Returns the validity time period in seconds for aCode
generated from this credential.byte[]
Returns the credential secret.int
hashCode()
static CredentialData
Parses an otpauth:// URI.
-
Field Details
-
DEFAULT_TOTP_PERIOD
public static final int DEFAULT_TOTP_PERIODThe default time period for TOTP Credentials.- See Also:
-
DEFAULT_DIGITS
public static final int DEFAULT_DIGITSThe default number of digits for calculatedCode
s.- See Also:
-
-
Constructor Details
-
CredentialData
public CredentialData(String accountName, OathType oathType, HashAlgorithm hashAlgorithm, byte[] secret, int digits, int period, int counter, @Nullable String issuer) Constructs a new instance from the given parameters.- Parameters:
accountName
- the name/label of the account, typically a username or email addressoathType
- the OATH type of the credential (TOTP or HOTP)hashAlgorithm
- the hash algorithm used by the credential (SHA1, SHA265 or SHA 512)secret
- the secret key of the credential, in raw bytes (not Base32 encoded)digits
- the number of digits to display for generatedCode
speriod
- the validity period of generatedCode
s, in seconds, for a TOTP credentialcounter
- the initial counter value (initial moving factor) for a HOTP credential (typically this should be 0)issuer
- the name of the credential issuer (e.g. Google, Amazon, Facebook, etc.)
-
-
Method Details
-
parseUri
Parses an otpauth:// URI.Example URI:
otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
- Parameters:
uri
- the otpauth:// URI to parse- Throws:
ParseUriException
- if the URI format is invalid
-
getId
public byte[] getId()Returns the credentials ID, as used to identify it on a YubiKey.The Credential ID is calculated based on the combination of the issuer, the name, and (for TOTP credentials) the validity period.
-
getAccountName
Returns the name of the credential. -
getOathType
Returns the OATH type (HOTP or TOTP) of the credential. -
getHashAlgorithm
Returns the hash algorithm used by the credential. -
getSecret
public byte[] getSecret()Returns the credential secret. -
getIssuer
Returns the name of the credential issuer. -
getDigits
public int getDigits()Returns the number of digits inCode
s calculated from the credential.- Returns:
- number of digits in code
-
getPeriod
public int getPeriod()Returns the validity time period in seconds for aCode
generated from this credential. -
getCounter
public int getCounter()Returns the initial counter value for a HOTP credential. -
equals
-
hashCode
public int hashCode()
-