类 SaTotpTemplate
java.lang.Object
cn.dev33.satoken.secure.totp.SaTotpTemplate
TOTP 算法类,支持 生成/验证 动态一次性密码
- 从以下版本开始:
- 1.42.0
- 作者:
- click33
-
字段概要
字段修饰符和类型字段说明int生成的验证码位数哈希算法(HmacSHA1、HmacSHA256等)int密钥长度(字节,推荐16或32)int时间窗口步长(秒) -
构造器概要
构造器构造器说明构造函数 (使用默认参数)SaTotpTemplate(int timeStep, int codeDigits, String hmacAlgorithm, int secretKeyLength) 构造函数 (使用自定义参数) -
方法概要
修饰符和类型方法说明_generateTOTP(String secretKey) 生成当前时间的 TOTP 验证码protected String_generateTOTP(String secretKey, long time) void校验用户输入的TOTP是否有效,如果无效则抛出异常generateGoogleSecretKey(String account) 生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{account}?generateGoogleSecretKey(String account, String secretKey) 生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{account}?generateGoogleSecretKey(String account, String issuer, String secretKey) 生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{issuer}:{account}?生成随机密钥(Base32编码)booleanvalidateTOTP(String secretKey, String code, int timeWindowOffset) 判断用户输入的 TOTP 是否有效
-
字段详细资料
-
timeStep
public int timeStep时间窗口步长(秒) -
codeDigits
public int codeDigits生成的验证码位数 -
hmacAlgorithm
哈希算法(HmacSHA1、HmacSHA256等) -
secretKeyLength
public int secretKeyLength密钥长度(字节,推荐16或32)
-
-
构造器详细资料
-
SaTotpTemplate
public SaTotpTemplate()构造函数 (使用默认参数) -
SaTotpTemplate
构造函数 (使用自定义参数)- 参数:
timeStep- 时间窗口步长(秒)codeDigits- 生成的验证码位数hmacAlgorithm- 哈希算法(HmacSHA1、HmacSHA256等)secretKeyLength- 密钥长度(字节,推荐16或32)
-
-
方法详细资料
-
generateSecretKey
生成随机密钥(Base32编码)- 返回:
- /
-
_generateTOTP
生成当前时间的 TOTP 验证码- 参数:
secretKey- Base32 编码的密钥- 返回:
- /
-
validateTOTP
判断用户输入的 TOTP 是否有效- 参数:
secretKey- Base32编码的密钥code- 用户输入的验证码timeWindowOffset- 允许的时间窗口偏移量(如1表示允许前后各1个时间窗口)- 返回:
- /
-
checkTOTP
校验用户输入的TOTP是否有效,如果无效则抛出异常- 参数:
secretKey- Base32编码的密钥code- 用户输入的验证码timeWindowOffset- 允许的时间窗口偏移量(如1表示允许前后各1个时间窗口)
-
generateGoogleSecretKey
生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{account}?secret={secretKey})- 参数:
account- 账户名- 返回:
- /
-
generateGoogleSecretKey
生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{account}?secret={secretKey})- 参数:
account- 账户名secretKey- TOTP 秘钥- 返回:
- /
-
generateGoogleSecretKey
生成谷歌认证器的扫码字符串 (形如:otpauth://totp/{issuer}:{account}?secret={secretKey}&issuer={issuer})- 参数:
account- 账户名issuer- 签发者secretKey- TOTP 秘钥- 返回:
- /
-
_generateTOTP
-