From 8cff63b0fcfebdf9a6c88766edfbc43919bbfaba Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Wed, 2 Apr 2025 23:12:55 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=A8=20TOTP=20=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=99=A8=E7=9B=B8=E5=85=B3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/up/password-secure.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sa-token-doc/up/password-secure.md b/sa-token-doc/up/password-secure.md index 2c1af193..2b029fc7 100644 --- a/sa-token-doc/up/password-secure.md +++ b/sa-token-doc/up/password-secure.md @@ -92,6 +92,29 @@ System.out.println("Base32解码后:" + text2); ``` +### TOTP 验证器 + +``` java +// 1、生成密钥 +String secretKey = SaTotpUtil.generateSecretKey(); +System.out.println("TOTP 秘钥: " + secretKey); + +// 2、生成扫码字符串 +String qeString = SaTotpUtil.generateGoogleSecretKey("zhangsan", secretKey); +System.out.println("扫码字符串: " + qeString); + +// 3、计算当前 TOTP 码 +String code = SaTotpUtil.generateTOTP(secretKey); +System.out.println("当前时间戳对应的 TOTP 码: " + code); + +// 4、验证用户输入 +boolean isValid = SaTotpUtil.validateTOTP(secretKey, code, 1); +System.out.println("验证结果: " + isValid); +``` + +在线 TOTP 管理器推荐: [TOTP 密码生成管理 - 工具哇](https://toolwa.com/totp/) + + ### BCrypt加密 由它加密的文件可在所有支持的操作系统和处理器上进行转移