Package com.bastiaanjansen.otp
Class HOTPGenerator
java.lang.Object
com.bastiaanjansen.otp.OTPGenerator
com.bastiaanjansen.otp.HOTPGenerator
public class HOTPGenerator extends OTPGenerator
Generates counter-based one-time passwords
- Author:
- Bastiaan Jansen
- See Also:
OTPGenerator
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHOTPGenerator.Builder -
Field Summary
-
Constructor Summary
Constructors Constructor Description HOTPGenerator(int passwordLength, HMACAlgorithm algorithm, byte[] secret)Constructs generator with custom password length -
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.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
-