注册
登录
添加依赖
<dependency>
<groupId>com.amdelamar</groupId>
<artifactId>jotp</artifactId>
<version>1.3.0</version>
</dependency>
执行下面代码
public class TOTPTest {
public static void main(String[] args) throws Exception{
// Generate a Time-based OTP from the secret, using Unix-time
// rounded down to the nearest 30 seconds.
String hexTime = OTP.timeInHex(System.currentTimeMillis(), 30);
String secret="123456";// github 的 secrt码
String code = OTP.create(secret, hexTime, 6, Type.TOTP);
System.out.println(code);
}
}