Class HMACProvider
java.lang.Object
io.github.pratiyush.totp.internal.HMACProvider
Secure HMAC computation for TOTP.
This utility class provides thread-safe HMAC calculation using the Java Cryptography Architecture (JCA).
Thread Safety
This class is thread-safe. Each call creates a fresh Mac instance.
Security Notes
- Uses standard JCA providers (no external crypto libraries)
- Validates algorithm availability before use
- Clear error messages for debugging (no secret leakage)
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Computes HMAC using the specified algorithm.static byte[]Computes HMAC using the specified algorithm name.static booleanisAlgorithmAvailable(Algorithm algorithm) Checks if an algorithm is available in the current JVM.static booleanisAlgorithmAvailable(String algorithmName) Checks if an algorithm is available in the current JVM.
-
Method Details
-
compute
Computes HMAC using the specified algorithm.- Parameters:
algorithm- the HMAC algorithmkey- the secret keydata- the data to authenticate- Returns:
- the HMAC result
- Throws:
TOTPException- if HMAC computation fails
-
compute
Computes HMAC using the specified algorithm name.- Parameters:
algorithmName- the JCA algorithm name (e.g., "HmacSHA256")key- the secret keydata- the data to authenticate- Returns:
- the HMAC result
- Throws:
TOTPException- if HMAC computation fails
-
isAlgorithmAvailable
Checks if an algorithm is available in the current JVM.- Parameters:
algorithm- the algorithm to check- Returns:
- true if the algorithm is available
-
isAlgorithmAvailable
Checks if an algorithm is available in the current JVM.- Parameters:
algorithmName- the JCA algorithm name- Returns:
- true if the algorithm is available
-