com.ibm.security.access.mobile.authorization

Class TotpGeneratorContext

    • Constructor Summary

      Constructors 
      Constructor and Description
      TotpGeneratorContext(java.lang.String secret, int digits, HmacAlgorithm algorithm)
      Returns a new TotpGeneratorContext object with the values secret, digits and algorithm.
      TotpGeneratorContext(java.lang.String secret, int digits, HmacAlgorithm algorithm, int period)
      Returns a new TotpGeneratorContext object with the values secret, digits, algorithm and period.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String create()
      Returns a time-based one-time password for the current time of the system
      java.lang.String create(int timeInterval)
      Returns a time-based one-time password based on T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT) and the given period in seconds.
      java.lang.String create(long timeInMillis)
      Returns a time-based one-time password based on T0 (Thu, 01 Jan 1970 00:00:00 UTC), the given UTC time in milliseconds and the period period set for this instance.
      static int remainingTime(int period)
      Calculates the remaining time for a given period in seconds, based on T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT)
      • Methods inherited from class java.lang.Object

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

      • TotpGeneratorContext

        public TotpGeneratorContext(java.lang.String secret,
                                    int digits,
                                    HmacAlgorithm algorithm)
        Returns a new TotpGeneratorContext object with the values secret, digits and algorithm. Initialization returns null if digits length is invalid outside the range
        Parameters:
        secret - the secret key used to generate the password.
        digits - a value of 6 or 8 representing the length of the password to be generated. The default is 6.
        algorithm - the HmacAlgorithm used to generate the password. The default is HmacAlgorithmSHA1.
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments is null or out of boundaries
      • TotpGeneratorContext

        public TotpGeneratorContext(java.lang.String secret,
                                    int digits,
                                    HmacAlgorithm algorithm,
                                    int period)
        Returns a new TotpGeneratorContext object with the values secret, digits, algorithm and period. Initialization returns null if digits length is invalid or period is outside the range.
        Parameters:
        secret - the secret key used to generate the password.
        digits - a value of 6 or 8 representing the length of the password to be generated. The default is 6.
        algorithm - the HmacAlgorithm used to generate the password. The default is HmacAlgorithmSHA1.
        period - a value between 10 and 300 representing the number of seconds the password is valid. Default is 30.
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments is null or out of boundaries
    • Method Detail

      • create

        public java.lang.String create(long timeInMillis)
                                throws java.lang.IllegalArgumentException
        Returns a time-based one-time password based on T0 (Thu, 01 Jan 1970 00:00:00 UTC), the given UTC time in milliseconds and the period period set for this instance.

        Ensure that the parameter has the correct type (long). Otherwise create(int) will be called.
        Parameters:
        timeInMillis - the UTC time in milliseconds
        Returns:
        the generated time-based one-time password by the 'Message Authentication Code' object (MAC)
        Throws:
        java.lang.IllegalArgumentException - if timeInMillis is < 0
      • create

        public java.lang.String create()
        Returns a time-based one-time password for the current time of the system
        Returns:
        the generated time-based one-time password by the 'Message Authentication Code' object (MAC)
      • create

        public java.lang.String create(int timeInterval)
        Returns a time-based one-time password based on T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT) and the given period in seconds.
        Parameters:
        timeInterval - represents the time step in seconds, has to be > 0 and < 300
        Returns:
        the generated time-based one-time password by the 'Message Authentication Code' object (MAC)
        Throws:
        java.lang.IllegalArgumentException - if timeInterval is < 10 or > 300
      • remainingTime

        public static int remainingTime(int period)
        Calculates the remaining time for a given period in seconds, based on T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT)
        Parameters:
        period - the period in seconds where the remaining time is needed, has to be > 0
        Returns:
        the remaining time in seconds
        Throws:
        java.lang.IllegalArgumentException - if parameter is <= 0