public class HmacOneTimePasswordGenerator extends Object
Generates HMAC-based one-time passwords (HOTP) as specified in RFC 4226.
HmacOneTimePasswordGenerator instances are thread-safe and may be shared and re-used across multiple
threads.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PASSWORD_LENGTH
The default length, in decimal digits, for one-time passwords.
|
static String |
HOTP_HMAC_ALGORITHM
The HMAC algorithm specified by the HOTP standard.
|
| Constructor and Description |
|---|
HmacOneTimePasswordGenerator()
Creates a new HMAC-based one-time password (HOTP) generator using a default password length
(6 digits).
|
HmacOneTimePasswordGenerator(int passwordLength)
Creates a new HMAC-based one-time password (HOTP) generator using the given password length.
|
| Modifier and Type | Method and Description |
|---|---|
int |
generateOneTimePassword(Key key,
long counter)
Generates a one-time password using the given key and counter value.
|
String |
getAlgorithm()
Returns the name of the HMAC algorithm used by this generator.
|
int |
getPasswordLength()
Returns the length, in decimal digits, of passwords produced by this generator.
|
public static final int DEFAULT_PASSWORD_LENGTH
public static final String HOTP_HMAC_ALGORITHM
public HmacOneTimePasswordGenerator()
throws NoSuchAlgorithmException
NoSuchAlgorithmException - if the underlying JRE doesn't support the
"HmacSHA1" algorithm, which should never
happen except in cases of serious misconfigurationpublic HmacOneTimePasswordGenerator(int passwordLength)
throws NoSuchAlgorithmException
passwordLength - the length, in decimal digits, of the one-time passwords to be generated; must be between
6 and 8, inclusiveNoSuchAlgorithmException - if the underlying JRE doesn't support the
"HmacSHA1" algorithm, which should never
happen except in cases of serious misconfigurationpublic int generateOneTimePassword(Key key, long counter) throws InvalidKeyException
key - a secret key to be used to generate the passwordcounter - the counter value to be used to generate the passwordInvalidKeyException - if the given key is inappropriate for initializing the Mac for this generatorpublic int getPasswordLength()
public String getAlgorithm()
Copyright © 2016–2018. All rights reserved.