public class HOTPAlgorithm extends Object
Modifier and Type | Method and Description |
---|---|
static int |
calcChecksum(long num,
int digits)
Calculates the checksum using the credit card algorithm.
|
static String |
generateOTP(byte[] secret,
long movingFactor,
int codeDigits,
boolean addChecksum,
int truncationOffset)
This method generates an OTP value for the given
set of parameters.
|
static byte[] |
hmac_sha1(byte[] keyBytes,
byte[] text)
This method uses the JCE to provide the HMAC-SHA-1 algorithm.
|
public static int calcChecksum(long num, int digits)
num
- the number to calculate the checksum fordigits
- number of significant places in the numberpublic static byte[] hmac_sha1(byte[] keyBytes, byte[] text) throws NoSuchAlgorithmException, InvalidKeyException
keyBytes
- the bytes to use for the HMAC-SHA-1 keytext
- the message or text to be authenticated.NoSuchAlgorithmException
- if no provider makes
either HmacSHA1 or HMAC-SHA-1
digest algorithms available.InvalidKeyException
- The secret provided was not a valid HMAC-SHA-1 key.public static String generateOTP(byte[] secret, long movingFactor, int codeDigits, boolean addChecksum, int truncationOffset) throws NoSuchAlgorithmException, InvalidKeyException
secret
- the shared secretmovingFactor
- the counter, time, or other value that
changes on a per use basis.codeDigits
- the number of digits in the OTP, not
including the checksum, if any.addChecksum
- a flag that indicates if a checksum digit
should be appended to the OTP.truncationOffset
- the offset into the MAC result to
begin truncation. If this value is out of
the range of 0 ... 15, then dynamic
truncation will be used.
Dynamic truncation is when the last 4
bits of the last byte of the MAC are
used to determine the start offset.NoSuchAlgorithmException
- if no provider makes
either HmacSHA1 or HMAC-SHA-1
digest algorithms available.InvalidKeyException
- The secret provided was not
a valid HMAC-SHA-1 key.Copyright © 2010–2025 Open Identity Platform Community. All rights reserved.