【问题标题】:Why ASP.Identy encodes SecurityStamp using Base32 (internal implementation)为什么 ASP.Identy 使用 Base32 对 SecurityStamp 进行编码(内部实现)
【发布时间】:2020-05-16 22:16:11
【问题描述】:

我正在考虑使用 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

【问题讨论】:

    标签: security asp.net-core asp.net-identity


    【解决方案1】:

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

    当您进一步检查 UserManager 源代码时,您会看到 NewSecurityStampGenerateNewAuthenticatorKey 引用,我相信它的目的是提供人类可读的输出(例如,设置 2FA)没有要扫描的二维码)。

    【讨论】:

    • 对于 authentication-key 确实有意义,但对于 security-stamp 它不会引入任何价值。正如我在问题中提到的那样,最终用户不应该直接阅读或使用它。在大小方面,base64 更有效。
    猜你喜欢
    • 2012-06-16
    • 2011-07-14
    • 2012-12-14
    • 2014-04-18
    • 1970-01-01
    • 2019-06-13
    • 2011-08-28
    • 2023-02-24
    • 1970-01-01
    相关资源
    最近更新 更多