Package com.bastiaanjansen.otp
Class HOTPGenerator
java.lang.Object
com.bastiaanjansen.otp.OTPGenerator
com.bastiaanjansen.otp.HOTPGenerator
Generates counter-based one-time passwords
- Author:
- Bastiaan Jansen
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class com.bastiaanjansen.otp.OTPGenerator
algorithm, passwordLength, secret -
Constructor Summary
ConstructorsConstructorDescriptionHOTPGenerator(int passwordLength, HMACAlgorithm algorithm, byte[] secret) Constructs generator with custom password length -
Method Summary
Modifier and TypeMethodDescriptiongenerate(long counter) Generate a counter-based one-time passwordCreate an OTPAuth URI for easy user on-boarding with only an issuerCreate an OTPAuth URI for easy user on-boarding with an issuer and account nameMethods inherited from class com.bastiaanjansen.otp.OTPGenerator
generateCode, getAlgorithm, getPasswordLength, getSecret, getURI, verify, verify
-
Constructor Details
-
HOTPGenerator
Constructs generator with custom password length- Parameters:
passwordLength- number of digits for generated code in range 6...8algorithm- HMAC hash algorithm used to hash datasecret- used to generate hash
-
-
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
-