Class DefaultCodeGenerator
java.lang.Object
com.iizix.totp.DefaultCodeGenerator
- All Implemented Interfaces:
CodeGenerator
The RFC 4226 / RFC 6238 code generator: HMAC of the big-endian 8-byte counter with the Base32-decoded secret, dynamic truncation, modulo 10^digits, zero-padded.
Constructor Summary
ConstructorsConstructorDescriptionConstructs a generator with the defaults: SHA256 and 6 digits.DefaultCodeGenerator(HashingAlgorithm algorithm) Constructs a 6 digit generator.DefaultCodeGenerator(HashingAlgorithm algorithm, int digits) Constructs a generator.Method Summary
Constructor Details
DefaultCodeGenerator
public DefaultCodeGenerator()Constructs a generator with the defaults: SHA256 and 6 digits.DefaultCodeGenerator
Constructs a 6 digit generator.- Parameters:
algorithm- The hashing algorithm.- Throws:
NullPointerException- Ifalgorithmisnull.
DefaultCodeGenerator
Constructs a generator.- Parameters:
algorithm- The hashing algorithm.digits- The number of digits, at least 1.- Throws:
NullPointerException- Ifalgorithmisnull.IllegalArgumentException- Ifdigitsis less than 1.
Method Details
generate
- Specified by:
generatein interfaceCodeGenerator- Parameters:
key- The shared secret/key to generate the code with.counter- The current time bucket number. Number of seconds since epoch / bucket period.- Returns:
- The n-digit code for the secret/counter.
- Throws:
CodeGenerationException- Thrown if the code generation fails for any reason.