Class CredentialData

java.lang.Object
com.yubico.yubikit.oath.CredentialData
All Implemented Interfaces:
Serializable

public class CredentialData extends Object implements Serializable
Data object holding all required information to add a new Credential to a YubiKey.
See Also:
  • Field Details

    • DEFAULT_TOTP_PERIOD

      public static final int DEFAULT_TOTP_PERIOD
      The default time period for TOTP Credentials.
      See Also:
    • DEFAULT_DIGITS

      public static final int DEFAULT_DIGITS
      The default number of digits for calculated Codes.
      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 address
      oathType - 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 generated Codes
      period - the validity period of generated Codes, in seconds, for a TOTP credential
      counter - 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

      public static CredentialData parseUri(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 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 String getIssuer()
      Returns the name of the credential issuer.
    • getDigits

      public int getDigits()
      Returns the number of digits in Codes calculated from the credential.
      Returns:
      number of digits in code
    • getPeriod

      public int getPeriod()
      Returns the validity time period in seconds for a Code generated from this credential.
    • getCounter

      public int getCounter()
      Returns the initial counter value for a HOTP credential.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object