惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
V
V2EX
博客园 - 【当耐特】
Vercel News
Vercel News
雷峰网
雷峰网
爱范儿
爱范儿
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
NISL@THU
NISL@THU
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
P
Proofpoint News Feed
B
Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
K
Kaspersky official blog
I
InfoQ
Google Online Security Blog
Google Online Security Blog
L
LINUX DO - 最新话题
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
V
Visual Studio Blog
AI
AI
Schneier on Security
Schneier on Security
B
Blog RSS Feed
T
Tor Project blog
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
V2EX - 技术
V2EX - 技术
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
Arctic Wolf
Webroot Blog
Webroot Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main

博客园 - 华安

Unity 相机:正交 (Orthographic) vs 透视 (Perspective) - 华安 unity中的button中的onclick控制面板中四个参数的意思分别是什么 - 华安 微信小程序开发中触发 onshow的几种特殊情况 SQL Server备份心得 MYSQL 备份数据库 微信与支付支付功能开发 微信小程序中页面配置下拉刷新 unity中 相机没有视锥效果线框了,如何打开 JSONPath表达式 C# 中的操作JSON类 JObject cookie中的 HttpOnly 、Secure、SameSite 解释 Spring-boot 中基于 IP 的限流和自动封禁 Filter 利用Spring Boot的 filter 结合ConcurrentHashMap 实现“同一IP每分钟最多允许300个404请求,超出后禁用30分钟访问” pixi-filters中的BackdropBlurFilter使用注意事项 PixiJS中的 SplitBitmapText.chars中的每个 BitmapText的x值分析 legend隐藏不想显示的图例 spring-boot HttpServletResponse response.sendRedirect是会跳转到 http而不是https springboot获取post请求参数 Javascript如何判断是触摸屏还是PC端 JavaScript获取鼠标点一个元素,获取鼠标点击的元素内的位置 spring-boot中配置Mongodbd的问题小结 Rest Template中添加 PATCH请求。 CSS实现修改CheckBox样式 SpringBoot+Thyemleaf报错:Error resolving template Template might not exist or might not be accessible div display flex 如何出现横向滚动条
登录 用 HMAC-SHA256 实现 TwoFA(二重验证)的坑
华安 · 2026-01-27 · via 博客园 - 华安

今天按照客户的要求,用 HMAC-SHA256 实现 TwoFA(二重验证),刚开始是用 HmacSHA1 实现的,客户端 用 Microsoft Authenticator扫码,是完全正常的。

但是我换成 用 HMAC-SHA256 算法后,无论怎么用 Microsoft Authenticator 都不能成功。

生成的验证代码:

otpauth://totp/xxx.com:admin?secret=KLWKVCOK3BI6WGN6ADDWWMTELMW55P5L&issuer=xxx.com&algorithm=SHA256&digits=6&period=30

我看代码就是 SHA256,没错。就这问题我消耗了整整半天。

最后在网上看到以为大神的留言。Microsoft Authenticator实际使用 SHA1,尽管 URI 指定了 SHA256.

我立马更改 校验动态码的算法,改成用SHA1来校验,正确。

由此可以断定 Microsoft Authenticator实际使用 SHA1,尽管 URI 指定了 SHA256.

总结:

用SHA1生成的动态码,必须用 SHA1算法来校验。

用SHA256生成的动态码,必须用 SHA256算法来校验。

我们在校验的时候,无法限制客户端时用 SHA1生成的动态码,还是 SHA256生成的动态码。

所以我们两个算法都要写。只要有一个校验正确就行。

譬如:Microsoft Authenticator我在 otpauth中写了 SHA256算法,但是生成动态码还是使用的SHA1算法,控制不了。

无论使用 SHA1和SHA256生成的密匙,在SHA1和SHA256校验的时候都可以通用。因为密匙生成的时候与算法无关,就是一个动态的字符串。

生成的动态验证码是否正确,可以用这个来校验  https://totp.danhersam.com/  不过这个是用 SHA1生成的动态验证码。输入用户对应的 Your Secret Key就可以了。其它不用改。