public final class GoogleAuthenticator extends Object implements IGoogleAuthenticator
该类允许用户创建一个新的16位base32编码的密钥 该密钥具有在{@code time=0}(UNIX纪元)计算的验证码和Google提供的QR条形码的URL,以便用户将生成的信息加载到Google Authenticator中。
此类使用的随机数生成器使用默认算法和提供程序。 用户可以通过将以下系统属性设置为自己选择的算法和提供程序名称来覆盖它们:
此类不会以任何方式存储生成的密钥或授权过程中传递的密钥。
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
RNG_ALGORITHM
The system property to specify the random number generator algorithm to use.
|
static String |
RNG_ALGORITHM_PROVIDER
The system property to specify the random number generator provider to use.
|
static int |
SCRATCH_CODE_MODULUS
Modulus used to truncate the scratch code.
|
| 构造器和说明 |
|---|
GoogleAuthenticator()
The constructor that uses the default config, random number algorithm, and random number algorithm provider.
|
GoogleAuthenticator(GoogleAuthenticatorConfig config)
The constructor that allows a user to specify the config and uses the default randomNumberAlgorithm and randomNumberAlgorithmProvider.
|
GoogleAuthenticator(GoogleAuthenticatorConfig config,
String randomNumberAlgorithm,
String randomNumberAlgorithmProvider)
The constructor that allows a user to specify the config, the randomNumberAlgorithm, and the randomNumberAlgorithmProvider.
|
GoogleAuthenticator(String randomNumberAlgorithm,
String randomNumberAlgorithmProvider)
The constructor that allows a user the randomNumberAlgorithm, the randomNumberAlgorithmProvider, and uses the default config.
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
authorize(String secret,
int verificationCode)
使用当前时间对照密钥检查验证码
|
boolean |
authorize(String secret,
int verificationCode,
long time)
使用指定的时间对照密钥检查验证码。
|
boolean |
authorizeUser(String userName,
int verificationCode)
此方法验证指定用户的验证码,该用户的私钥是使用当前时间从配置的凭据存储库中检索到的。
|
boolean |
authorizeUser(String userName,
int verificationCode,
long time)
此方法验证指定用户的验证代码,该用户的私钥是从配置的凭据存储库中检索到的。
|
GoogleAuthenticatorKey |
createCredentials()
此方法生成一组新的凭证,包括:
密钥
验证代码
临时代码列表
The user must register this secret on their device.
|
GoogleAuthenticatorKey |
createCredentials(String userName)
此方法生成一组新的凭据,调用
#createCredentials method with no arguments. |
ICredentialRepository |
getCredentialRepository()
此方法加载使用Java服务加载器API注册的第一个可用ICredentialRepository
|
int |
getTotpPassword(String secret)
此方法生成当前的TOTP密码。
|
int |
getTotpPassword(String secret,
long time)
此方法在指定时间生成TOTP密码。
|
int |
getTotpPasswordOfUser(String userName)
此方法生成当前的TOTP密码。
|
int |
getTotpPasswordOfUser(String userName,
long time)
此方法在指定时间生成TOTP密码
|
GoogleAuthenticatorKey |
parseGoogleAuthenticatorKey(String secret) |
String |
parseTotpCode(int code)
Int to String 补位
|
void |
setCredentialRepository(ICredentialRepository repository)
手动装载存储库
|
public static final String RNG_ALGORITHM
public static final String RNG_ALGORITHM_PROVIDER
public static final int SCRATCH_CODE_MODULUS
public GoogleAuthenticator()
public GoogleAuthenticator(GoogleAuthenticatorConfig config)
config - The configuration used by the current instance.public GoogleAuthenticator(String randomNumberAlgorithm, String randomNumberAlgorithmProvider)
randomNumberAlgorithm - The random number algorithm to define the secure random number generator. If this is null the randomNumberAlgorithmProvider must be null.randomNumberAlgorithmProvider - The random number algorithm provider to define the secure random number generator. This value may be null.public GoogleAuthenticator(GoogleAuthenticatorConfig config, String randomNumberAlgorithm, String randomNumberAlgorithmProvider)
config - The configuration used by the current instance.randomNumberAlgorithm - The random number algorithm to define the secure random number generator. If this is null the randomNumberAlgorithmProvider must be null.randomNumberAlgorithmProvider - The random number algorithm provider to define the secure random number generator. This value may be null.public GoogleAuthenticatorKey createCredentials()
IGoogleAuthenticatorThe user must register this secret on their device.
createCredentials 在接口中 IGoogleAuthenticatorpublic GoogleAuthenticatorKey createCredentials(String userName)
IGoogleAuthenticator#createCredentials method with no arguments. The generated
credentials are then saved using the configured
#ICredentialRepository service.
用户必须在他们的设备上注册这个服务。
createCredentials 在接口中 IGoogleAuthenticatoruserName - the user name.public int getTotpPassword(String secret)
IGoogleAuthenticatorgetTotpPassword 在接口中 IGoogleAuthenticatorsecret - the encoded secret key.public int getTotpPassword(String secret, long time)
IGoogleAuthenticatorgetTotpPassword 在接口中 IGoogleAuthenticatorsecret - The encoded secret key.time - The time to use to calculate the password.public int getTotpPasswordOfUser(String userName)
IGoogleAuthenticatorgetTotpPasswordOfUser 在接口中 IGoogleAuthenticatoruserName - The user whose password must be created.public int getTotpPasswordOfUser(String userName, long time)
IGoogleAuthenticatorgetTotpPasswordOfUser 在接口中 IGoogleAuthenticatoruserName - The user whose password must be created.time - The time to use to calculate the password.public boolean authorize(String secret, int verificationCode)
IGoogleAuthenticatorauthorize 在接口中 IGoogleAuthenticatorsecret - the encoded secret key.verificationCode - the verification code.true if the validation code is valid,
false otherwise.IGoogleAuthenticator.authorize(String, int, long)public boolean authorize(String secret, int verificationCode, long time)
IGoogleAuthenticatorwindowSize property of this class.
间隔大小使用RFC 6238推荐的默认值30秒。
authorize 在接口中 IGoogleAuthenticatorsecret - The encoded secret key.verificationCode - The verification code.time - The time to use to calculate the TOTP password.true if the validation code is valid, false
otherwise.public boolean authorizeUser(String userName, int verificationCode)
IGoogleAuthenticatorIGoogleAuthenticator.authorizeUser(String, int, long).authorizeUser 在接口中 IGoogleAuthenticatoruserName - 要验证其验证码的用户。verificationCode - The validation code.true if the validation code is valid,
false otherwise.IGoogleAuthenticator.authorize(String, int)public boolean authorizeUser(String userName, int verificationCode, long time)
IGoogleAuthenticatorIGoogleAuthenticator.authorize(String, int, long) method.authorizeUser 在接口中 IGoogleAuthenticatoruserName - The user whose verification code is to be
validated.verificationCode - The validation code.time - The time to use to calculate the TOTP password.true if the validation code is valid,
false otherwise.IGoogleAuthenticator.authorize(String, int)public ICredentialRepository getCredentialRepository()
getCredentialRepository 在接口中 IGoogleAuthenticatornull
if none is found.public void setCredentialRepository(ICredentialRepository repository)
setCredentialRepository 在接口中 IGoogleAuthenticatorrepository - The credential repository to use, or null to
disable this feature.public String parseTotpCode(int code)
code - 代码public GoogleAuthenticatorKey parseGoogleAuthenticatorKey(String secret)
Copyright © 2024. All rights reserved.