【发布时间】:2019-05-01 06:49:12
【问题描述】:
基于时间(20 秒有效期)的谷歌验证码,我需要在读取 4 位数代码之前检查时间。
- 使用TOTP收集谷歌验证码
- 在我们的应用程序中自动应用代码
问题, 读取时 - 边缘代码(18/19 秒),并自动将代码发送到我们的文本框,但有效性已过期且身份验证失败。所以我想检查代码以及有效期
一个。如果有效时间大于 10 秒,我可以获取代码并将其传递给文本框 湾。如果有效期小于10秒,等待10秒
代码:
public static String getTOTPCode(String secretKey) {
String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase();
Base32 base32 = new Base32();
byte[] bytes = base32.decode(normalizedBase32Key);
String hexKey = Hex.encodeHexString(bytes);
return TOTP.getOTP(hexKey);
}
jar 文件
commons-code1.8 jar
totp-1.0 jar
参考上面,告诉我如何获得OTP的有效时间?
【问题讨论】:
标签: java one-time-password google-authenticator totp