Class CredentialData

  • All Implemented Interfaces:
    java.io.Serializable

    public class CredentialData
    extends java.lang.Object
    implements java.io.Serializable
    Data object holding all required information to add a new Credential to a YubiKey.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_DIGITS
      The default number of digits for calculated Codes.
      static int DEFAULT_TOTP_PERIOD
      The 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.
    • 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 calculated Codes.
        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 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 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 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​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object