Class TOTP

    • Constructor Summary

      Constructors 
      Constructor Description
      TOTP()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 generateTotp​(java.lang.String key, java.lang.String time, int digits, java.lang.String crypto)
      Generates a TOTP value for the given set of parameters.
      java.lang.String getLabel()  
      protected static byte[] hexStringToBytes​(java.lang.String hex)
      Converts a Hex based string to byte[]
      • Methods inherited from class java.lang.Object

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

      • TOTP

        public TOTP()
    • 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. (TOTP base is time from UTC rounded to the half-second)
        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/rfc6238
      • hexStringToBytes

        protected static byte[] hexStringToBytes​(java.lang.String hex)
        Converts a Hex based string to byte[]
        Parameters:
        hex - the HEX string
        Returns:
        byte array
      • generateTotp

        protected static java.lang.String generateTotp​(java.lang.String key,
                                                       java.lang.String time,
                                                       int digits,
                                                       java.lang.String crypto)
                                                throws java.security.InvalidKeyException,
                                                       java.security.NoSuchAlgorithmException
        Generates a TOTP value for the given set of parameters.
        Parameters:
        key - the shared secret, HEX encoded
        time - a value that reflects a time
        digits - number of digits to return
        crypto - the crypto function to use
        Returns:
        numeric String in base 10 that includes digits
        Throws:
        java.security.NoSuchAlgorithmException - if hmac sha1 is not available
        java.security.InvalidKeyException - if given key is inappropriate for this mac