Class HOTP

    • Constructor Summary

      Constructors 
      Constructor Description
      HOTP()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static int checksum​(long num, int digits)
      Calculates the checksum using the credit card algorithm.
      java.lang.String create​(java.lang.String secret, java.lang.String base, int digits)
      Create a one-time-password with the given key, base, and digits.
      protected static java.lang.String generateHotp​(byte[] secret, long movingFactor, int digits, boolean addChecksum, int truncationOffset, java.lang.String crypto)
      This method generates an OTP value for the given set of parameters.
      java.lang.String getLabel()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HOTP

        public HOTP()
    • Method Detail

      • create

        public java.lang.String create​(java.lang.String secret,
                                       java.lang.String base,
                                       int digits)
                                throws java.security.InvalidKeyException,
                                       java.security.NoSuchAlgorithmException
        Create a one-time-password with the given key, base, and digits.
        Specified by:
        create in interface OTPInterface
        Parameters:
        secret - The secret. Shhhhhh!
        base - The offset. (HOTP is a counter incremented by each use)
        digits - The length of the code (Commonly '6')
        Returns:
        code
        Throws:
        java.security.NoSuchAlgorithmException - when HMAC is not available on this jvm
        java.security.InvalidKeyException - when secret is invalid
        See Also:
        https://tools.ietf.org/html/rfc4226
      • checksum

        protected static int checksum​(long num,
                                      int digits)
        Calculates the checksum using the credit card algorithm. This algorithm has the advantage that it detects any single mistyped digit and any single transposition of adjacent digits.
        Parameters:
        num - the number to calculate the checksum for
        digits - number of significant places in the number
        Returns:
        the checksum of num
      • generateHotp

        protected static java.lang.String generateHotp​(byte[] secret,
                                                       long movingFactor,
                                                       int digits,
                                                       boolean addChecksum,
                                                       int truncationOffset,
                                                       java.lang.String crypto)
                                                throws java.security.NoSuchAlgorithmException,
                                                       java.security.InvalidKeyException
        This method generates an OTP value for the given set of parameters.
        Parameters:
        secret - Shhhhh.
        movingFactor - the counter, time, or other value
        digits - length of the code
        addChecksum - a flag that indicates if the checksum digit should be appened to the OTP
        truncationOffset - the offset into the MAC result to begin truncation. If this value is out of the range of 0 ... 15, then dynamic truncation will be used. Dynamic truncation is when the last 4 bits of the last byte of the MAC are used to determine the start offset.
        crypto - the crypto function to use
        Returns:
        An OTP code.
        Throws:
        java.security.NoSuchAlgorithmException - if hmac sha1 is not available
        java.security.InvalidKeyException - if given key is inappropriate for this mac