Class Totp
java.lang.Object
io.getlime.security.powerauth.crypto.lib.totp.Totp
TOTP: Time-Based One-Time Password Algorithm according to RFC 6238.
- Author:
- Lubos Racansky, lubos.racansky@wultra.com
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]generateTotpSha256(byte[] key, Instant instant, int digitsNumber) Generates a TOTP value for the given set of parameters using HmacSHA256 algorithm.static byte[]generateTotpSha256(byte[] key, Instant instant, Duration stepLength, int digitsNumber) Generates a TOTP value for the given set of parameters using HmacSHA256 algorithm.static byte[]generateTotpSha512(byte[] key, Instant instant, int digitsNumber) Generates a TOTP value for the given set of parameters using HmacSHA512 algorithm.static byte[]generateTotpSha512(byte[] key, Instant instant, Duration stepLength, int digitsNumber) Generates a TOTP value for the given set of parameters using HmacSHA512 algorithm.static booleanvalidateTotpSha256(byte[] otp, byte[] key, Instant instant, int digitsNumber) Validate a TOTP value for the given set of parameters using HmacSHA256 algorithm.static booleanvalidateTotpSha256(byte[] otp, byte[] key, Instant instant, int digitsNumber, int steps, Duration stepLength) Validate a TOTP value for the given set of parameters using HmacSHA256 algorithm.static booleanvalidateTotpSha512(byte[] otp, byte[] key, Instant instant, int digitsNumber) Validate a TOTP value for the given set of parameters using HmacSHA512 algorithm.static booleanvalidateTotpSha512(byte[] otp, byte[] key, Instant instant, int digitsNumber, int steps, Duration stepLength) Validate a TOTP value for the given set of parameters using HmacSHA512 algorithm.
-
Method Details
-
generateTotpSha256
public static byte[] generateTotpSha256(byte[] key, Instant instant, int digitsNumber) throws CryptoProviderException Generates a TOTP value for the given set of parameters using HmacSHA256 algorithm.- Parameters:
key- the shared secretinstant- current Unix timedigitsNumber- number of digits to return- Returns:
- a numeric String in base 10 that includes truncation digits
- Throws:
CryptoProviderException- in case of any crypto error
-
generateTotpSha256
public static byte[] generateTotpSha256(byte[] key, Instant instant, Duration stepLength, int digitsNumber) throws CryptoProviderException Generates a TOTP value for the given set of parameters using HmacSHA256 algorithm.- Parameters:
key- the shared secretinstant- current Unix timestepLength- length of time stepdigitsNumber- number of digits to return- Returns:
- a numeric String in base 10 that includes truncation digits
- Throws:
CryptoProviderException- in case of any crypto error
-
generateTotpSha512
public static byte[] generateTotpSha512(byte[] key, Instant instant, int digitsNumber) throws CryptoProviderException Generates a TOTP value for the given set of parameters using HmacSHA512 algorithm.- Parameters:
key- the shared secretinstant- current Unix timedigitsNumber- number of digits to return- Returns:
- a numeric String in base 10 that includes truncation digits
- Throws:
CryptoProviderException- in case of any crypto error
-
generateTotpSha512
public static byte[] generateTotpSha512(byte[] key, Instant instant, Duration stepLength, int digitsNumber) throws CryptoProviderException Generates a TOTP value for the given set of parameters using HmacSHA512 algorithm.- Parameters:
key- the shared secretinstant- current Unix timestepLength- length of time stepdigitsNumber- number of digits to return- Returns:
- a numeric String in base 10 that includes truncation digits
- Throws:
CryptoProviderException- in case of any crypto error
-
validateTotpSha256
public static boolean validateTotpSha256(byte[] otp, byte[] key, Instant instant, int digitsNumber) throws CryptoProviderException Validate a TOTP value for the given set of parameters using HmacSHA256 algorithm. Validates one time step backward.- Parameters:
otp- TOTP to validatekey- the shared secretinstant- current Unix timedigitsNumber- expected length of the TOTP- Returns:
- true if OTP is valid
- Throws:
CryptoProviderException- in case of any crypto error- See Also:
-
validateTotpSha256
public static boolean validateTotpSha256(byte[] otp, byte[] key, Instant instant, int digitsNumber, int steps, Duration stepLength) throws CryptoProviderException Validate a TOTP value for the given set of parameters using HmacSHA256 algorithm.- Parameters:
otp- TOTP to validatekey- the shared secretinstant- current Unix timedigitsNumber- expected length of the TOTPsteps- number of backward time steps allowed to validatestepLength- length of time step- Returns:
- true if OTP is valid
- Throws:
CryptoProviderException- in case of any crypto error
-
validateTotpSha512
public static boolean validateTotpSha512(byte[] otp, byte[] key, Instant instant, int digitsNumber) throws CryptoProviderException Validate a TOTP value for the given set of parameters using HmacSHA512 algorithm. Validates one time step backward.- Parameters:
otp- TOTP to validatekey- the shared secretinstant- current Unix timedigitsNumber- expected length of the TOTP- Returns:
- true if OTP is valid
- Throws:
CryptoProviderException- in case of any crypto error- See Also:
-
validateTotpSha512
public static boolean validateTotpSha512(byte[] otp, byte[] key, Instant instant, int digitsNumber, int steps, Duration stepLength) throws CryptoProviderException Validate a TOTP value for the given set of parameters using HmacSHA512 algorithm.- Parameters:
otp- TOTP to validatekey- the shared secretinstant- current Unix timedigitsNumber- expected length of the TOTPsteps- number of backward time steps allowed to validatestepLength- length of time step- Returns:
- true if OTP is valid
- Throws:
CryptoProviderException- in case of any crypto error
-