Package tech.mgl.utils.security.gen
Class PasscodeGenerator
java.lang.Object
tech.mgl.utils.security.gen.PasscodeGenerator
An implementation of the HOTP generator specified by RFC 4226. Generates
short passcodes that may be used in challenge-response protocols or as
timeout passcodes that are only valid for a short period.
The default passcode is a 6-digit decimal code. The maximum passcode length is 9 digits.
- Author:
- sweis@google.com (Steve Weis)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPasscodeGenerator(Mac mac) PasscodeGenerator(Mac mac, int passCodeLength) PasscodeGenerator(tech.mgl.utils.security.gen.PasscodeGenerator.Signer signer) PasscodeGenerator(tech.mgl.utils.security.gen.PasscodeGenerator.Signer signer, int passCodeLength) -
Method Summary
Modifier and TypeMethodDescriptiongenerateResponseCode(byte[] challenge) generateResponseCode(long state) generateResponseCode(long state, byte[] challenge) booleanverifyResponseCode(long challenge, String response) booleanverifyTimeoutCode(long currentInterval, String timeoutCode) Verify a timeout code.booleanverifyTimeoutCode(String timeoutCode, long currentInterval, int pastIntervals, int futureIntervals) Verify a timeout code.
-
Field Details
-
INTERVAL
public static final int INTERVALDefault time interval- See Also:
-
-
Constructor Details
-
PasscodeGenerator
- Parameters:
mac- AMacused to generate passcodes
-
PasscodeGenerator
public PasscodeGenerator(tech.mgl.utils.security.gen.PasscodeGenerator.Signer signer) -
PasscodeGenerator
- Parameters:
mac- AMacused to generate passcodespassCodeLength- The length of the decimal passcode
-
PasscodeGenerator
public PasscodeGenerator(tech.mgl.utils.security.gen.PasscodeGenerator.Signer signer, int passCodeLength)
-
-
Method Details
-
generateResponseCode
- Parameters:
state- 8-byte integer value representing internal OTP state.- Returns:
- A decimal response code
- Throws:
GeneralSecurityException- If a JCE exception occur
-
generateResponseCode
- Parameters:
state- 8-byte integer value representing internal OTP state.challenge- Optional challenge as array of bytes.- Returns:
- A decimal response code
- Throws:
GeneralSecurityException- If a JCE exception occur
-
generateResponseCode
- Parameters:
challenge- An arbitrary byte array used as a challenge- Returns:
- A decimal response code
- Throws:
GeneralSecurityException- If a JCE exception occur
-
verifyResponseCode
- Parameters:
challenge- A challenge to check a response againstresponse- A response to verify- Returns:
- True if the response is valid
- Throws:
GeneralSecurityException
-
verifyTimeoutCode
public boolean verifyTimeoutCode(long currentInterval, String timeoutCode) throws GeneralSecurityException Verify a timeout code. The timeout code will be valid for a time determined by the interval period and the number of adjacent intervals checked.- Parameters:
timeoutCode- The timeout code- Returns:
- True if the timeout code is valid
- Throws:
GeneralSecurityException
-
verifyTimeoutCode
public boolean verifyTimeoutCode(String timeoutCode, long currentInterval, int pastIntervals, int futureIntervals) throws GeneralSecurityException Verify a timeout code. The timeout code will be valid for a time determined by the interval period and the number of adjacent intervals checked.- Parameters:
timeoutCode- The timeout codepastIntervals- The number of past intervals to checkfutureIntervals- The number of future intervals to check- Returns:
- True if the timeout code is valid
- Throws:
GeneralSecurityException
-