Package com.bastiaanjansen.otp
Class HOTPGenerator
java.lang.Object
com.bastiaanjansen.otp.OneTimePasswordGenerator
com.bastiaanjansen.otp.HOTPGenerator
public class HOTPGenerator extends OneTimePasswordGenerator
Generates counter-based one-time passwords
- Author:
- Bastiaan Jansen
- See Also:
OneTimePasswordGenerator
-
Field Summary
Fields inherited from class com.bastiaanjansen.otp.OneTimePasswordGenerator
algorithm, DEFAULT_HMAC_ALGORITHM, DEFAULT_PASSWORD_LENGTH, passwordLength, secret -
Constructor Summary
Constructors Constructor Description HOTPGenerator(int passwordLength, String secret)Constructs generator with custom password lengthHOTPGenerator(String secret)Constructs generator with default valuesHOTPGenerator(URI uri)Constructs generator from a OTPAuth URI -
Method Summary
Modifier and Type Method Description Stringgenerate(long counter)Generate a counter-based one-time passwordURIgetURI(int counter, String issuer)Create an OTPAuth URI for easy user on-boarding with only an issuerURIgetURI(int counter, String issuer, String account)Create an OTPAuth URI for easy user on-boarding with an issuer and account nameMethods inherited from class com.bastiaanjansen.otp.OneTimePasswordGenerator
generate, getAlgorithm, getPasswordLength, getSecret, getURI, verify, verify
-
Constructor Details
-
HOTPGenerator
Constructs generator with default values- Parameters:
secret- used to generate hash
-
HOTPGenerator
Constructs generator with custom password length- Parameters:
passwordLength- number of digits for generated code in range 6...8secret- used to generate hash
-
HOTPGenerator
Constructs generator from a OTPAuth URI- Parameters:
uri- OTPAuth URI- Throws:
UnsupportedEncodingException- when URI query can't be encodede
-
-
Method Details
-
generate
Generate a counter-based one-time password- Parameters:
counter- how many times time interval has passed since 1970- Returns:
- generated HOTP code
- Throws:
IllegalArgumentException- when code could not be generated
-
getURI
Create an OTPAuth URI for easy user on-boarding with only an issuer- Parameters:
counter- of URIissuer- name for URI- Returns:
- OTPAuth URI
- Throws:
URISyntaxException- when URI cannot be created
-
getURI
Create an OTPAuth URI for easy user on-boarding with an issuer and account name- Parameters:
counter- of URIissuer- name for URIaccount- name for URI- Returns:
- OTPAuth URI
- Throws:
URISyntaxException- when URI cannot be created
-