Modifier and Type | Field and Description |
---|---|
static Duration |
DEFAULT_TIME_STEP
默认步进 (30秒).
|
DEFAULT_PASSWORD_LENGTH, HOTP_HMAC_ALGORITHM
Constructor and Description |
---|
TOTP(byte[] key)
构造,使用默认HMAC算法(HmacSHA1)
|
TOTP(Duration timeStep,
byte[] key)
构造,使用默认HMAC算法(HmacSHA1)
|
TOTP(Duration timeStep,
int passwordLength,
byte[] key)
构造,使用默认HMAC算法(HmacSHA1)
|
TOTP(Duration timeStep,
int passwordLength,
HmacAlgorithm algorithm,
byte[] key)
构造
|
Modifier and Type | Method and Description |
---|---|
int |
generate(Instant timestamp)
使用给定的时间戳生成一次性密码.
|
static String |
generateGoogleSecretKey(String account,
int numBytes)
生成谷歌认证器的字符串(扫码字符串)
基于时间的,计数器不适合
|
Duration |
getTimeStep()
获取步进
|
boolean |
validate(Instant timestamp,
int offsetSize,
int code)
用于验证code是否正确
|
generate, generateSecretKey, getAlgorithm, getPasswordLength
public static final Duration DEFAULT_TIME_STEP
public TOTP(byte[] key)
key
- 共享密码,RFC 4226要求最少128位public TOTP(Duration timeStep, byte[] key)
timeStep
- 日期步进,用于生成移动因子(moving factor)key
- 共享密码,RFC 4226要求最少128位public TOTP(Duration timeStep, int passwordLength, byte[] key)
timeStep
- 日期步进,用于生成移动因子(moving factor)passwordLength
- 密码长度,可以是6,7,8key
- 共享密码,RFC 4226要求最少128位public TOTP(Duration timeStep, int passwordLength, HmacAlgorithm algorithm, byte[] key)
timeStep
- 日期步进,用于生成移动因子(moving factor)passwordLength
- 密码长度,可以是6,7,8algorithm
- HMAC算法枚举key
- 共享密码,RFC 4226要求最少128位public int generate(Instant timestamp)
timestamp
- 用于生成密码的时间戳public boolean validate(Instant timestamp, int offsetSize, int code)
timestamp
- 验证时间戳offsetSize
- 误差范围code
- codepublic static String generateGoogleSecretKey(String account, int numBytes)
account
- 账户名。numBytes
- 将生成的种子字节数量。public Duration getTimeStep()
Copyright © 2024. All rights reserved.