Package io.mangoo.utils
Class TotpUtils
java.lang.Object
io.mangoo.utils.TotpUtils
- Author:
- svenkubiak
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGenerates a 64 byte (512 bit) secretstatic StringgetOtpauthURL(String name, String issuer, String secret, HmacShaAlgorithm algorithm, String digits, String period) Generates an otpauth code to share a secret with a userstatic StringgetQRCode(String name, String issuer, String secret, HmacShaAlgorithm algorithm, String digits, String period) Generates a QR code link from Google charts API to share a secret with a userstatic StringCreates the current TOTP based on the following default values: SHA512 algorithm, 6 digits, 30 seconds time periodstatic StringgetTotp(String secret, HmacShaAlgorithm algorithm, int digits, int period) Creates the current TOTP based on the given parametersstatic booleanverifiedTotp(String secret, String totp) Verifies a given TOTP based on the following default values: SHA512 algorithm, 6 digits, 30 seconds time period
-
Method Details
-
createSecret
Generates a 64 byte (512 bit) secret- Returns:
- A 64 characters random string based on SecureRandom
-
getTotp
Creates the current TOTP based on the following default values: SHA512 algorithm, 6 digits, 30 seconds time period- Parameters:
secret- The secret to use- Returns:
- The totp value or null if generation failed
-
getTotp
Creates the current TOTP based on the given parameters- Parameters:
secret- The secret to usealgorithm- The algorithm to usedigits- The digits to use (6 or 8)period- The time period in seconds- Returns:
- The totp value or null if generation failed
-
verifiedTotp
Verifies a given TOTP based on the following default values: SHA512 algorithm, 6 digits, 30 seconds time period- Parameters:
secret- The secret to usetotp- The TOTP to verify- Returns:
- True if the TOTP is valid, false otherwise
-
getQRCode
public static String getQRCode(String name, String issuer, String secret, HmacShaAlgorithm algorithm, String digits, String period) Generates a QR code link from Google charts API to share a secret with a user- Parameters:
name- The name of the accountissuer- The name of the issuersecret- The secret to usealgorithm- The algorithm to usedigits- The number of digits to useperiod- The period to use- Returns:
- A URL to Google charts API with the QR code
-
getOtpauthURL
public static String getOtpauthURL(String name, String issuer, String secret, HmacShaAlgorithm algorithm, String digits, String period) Generates an otpauth code to share a secret with a user- Parameters:
name- The name of the accountissuer- The name of the issuersecret- The secret to usealgorithm- The algorithm to usedigits- The number of digits to useperiod- The period to use- Returns:
- An otpauth url
-