gpt4 book ai didi

security - 为什么 ASP.Identy 使用 Base32 对 SecurityStamp 进行编码(内部实现)

转载 作者:行者123 更新时间:2023-12-02 04:36:54 32 4
gpt4 key购买 nike

我正在考虑使用 Base64 将 SecurityStamp 存储在我的用户聚合中。在进入陷阱之前,我试图理解 ASP 团队选择使用 Base32 而不是简单地使用 Base64 的原因。

SecurityStamp 不是人类应该在请求中手动读取或传递的内容。我找不到添加内部 Base32 实现而不是使用现有 Base64 的任何明显优势。

private static string NewSecurityStamp()
{
byte[] bytes = new byte[20];
_rng.GetBytes(bytes);
return Base32.ToBase32(bytes);
}

https://github.com/dotnet/aspnetcore/blob/master/src/Identity/Extensions.Core/src/UserManager.cs#L2438

最佳答案

如果您查看字母表 Base32 is using ,您会发现它全部是大写字母和 234567。这样做是为了专门减少传输代码时的人为错误(请参阅 this SO answer 中的更多背景知识)。

当您进一步检查 UserManager 源代码时,您将看到 GenerateNewAuthenticatorKey 引用了 NewSecurityStamp ,我相信它旨在提供人类可读的输出(例如,当您没有可扫描的二维码时,请设置 2FA)。

关于security - 为什么 ASP.Identy 使用 Base32 对 SecurityStamp 进行编码(内部实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60000581/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com