Package com.yubico.yubikit.oath
Class CredentialData
- java.lang.Object
-
- com.yubico.yubikit.oath.CredentialData
-
- All Implemented Interfaces:
java.io.Serializable
public class CredentialData extends java.lang.Object implements java.io.SerializableData object holding all required information to add a newCredentialto a YubiKey.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DIGITSThe default number of digits for calculatedCodes.static intDEFAULT_TOTP_PERIODThe default time period for TOTP Credentials.
-
Constructor Summary
Constructors Constructor Description CredentialData(java.lang.String accountName, OathType oathType, HashAlgorithm hashAlgorithm, byte[] secret, int digits, int period, int counter, java.lang.String issuer)Constructs a new instance from the given parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)java.lang.StringgetAccountName()Returns the name of the credential.intgetCounter()Returns the initial counter value for a HOTP credential.intgetDigits()Returns the number of digits inCodes calculated from the credential.HashAlgorithmgetHashAlgorithm()Returns the hash algorithm used by the credential.byte[]getId()Returns the credentials ID, as used to identify it on a YubiKey.java.lang.StringgetIssuer()Returns the name of the credential issuer.OathTypegetOathType()Returns the OATH type (HOTP or TOTP) of the credential.intgetPeriod()Returns the validity time period in seconds for aCodegenerated from this credential.byte[]getSecret()Returns the credential secret.inthashCode()static CredentialDataparseUri(java.net.URI uri)Parses an otpauth:// URI.
-
-
-
Field Detail
-
DEFAULT_TOTP_PERIOD
public static final int DEFAULT_TOTP_PERIOD
The default time period for TOTP Credentials.- See Also:
- Constant Field Values
-
DEFAULT_DIGITS
public static final int DEFAULT_DIGITS
The default number of digits for calculatedCodes.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CredentialData
public CredentialData(java.lang.String accountName, OathType oathType, HashAlgorithm hashAlgorithm, byte[] secret, int digits, int period, int counter, @Nullable java.lang.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 generatedCodesperiod- the validity period of generatedCodes, 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 Detail
-
parseUri
public static CredentialData parseUri(java.net.URI uri) throws ParseUriException
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
public java.lang.String getAccountName()
Returns the name of the credential.
-
getOathType
public OathType getOathType()
Returns the OATH type (HOTP or TOTP) of the credential.
-
getHashAlgorithm
public HashAlgorithm getHashAlgorithm()
Returns the hash algorithm used by the credential.
-
getSecret
public byte[] getSecret()
Returns the credential secret.
-
getIssuer
@Nullable public java.lang.String getIssuer()
Returns the name of the credential issuer.
-
getDigits
public int getDigits()
Returns the number of digits inCodes calculated from the credential.- Returns:
- number of digits in code
-
getPeriod
public int getPeriod()
Returns the validity time period in seconds for aCodegenerated from this credential.
-
getCounter
public int getCounter()
Returns the initial counter value for a HOTP credential.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-