gpt4 book ai didi

c# - 如何对 `string.Empty` 进行哈希处理?

转载 作者:行者123 更新时间:2023-11-30 14:31:11 24 4
gpt4 key购买 nike

出于某种原因,这对我来说没有意义。当 string 中没有要散列的 char 时,如何散列空 string

我所说的看起来像这样:

System.Web.Helpers.Crypto.HashPassword(string.Empty);

这怎么可能?

最佳答案

来自 the MSDN :

The password hash is generated with the RFC 2898 algorithm using a 128-bit salt, a 256-bit subkey, and 1000 iterations. The format of the generated hash bytestream is {0x00, salt, subkey}, which is base-64 encoded before it is returned.

首先你需要了解如何RFC 2898 works .简而言之,它将盐与传入的密码结合起来,对其进行多次哈希处理,并生成一个字节流,您可以根据需要读取任意数量的字节。

使用上面引用的文档,我们看到它选择了一个 128 位大的随机盐,使用 1000 个哈希值,并在最后从流中提取 256 位。

所以我们可以得到字符,因为 RFC 2898 允许您从函数的输出中获取任意多的字节,它不是固定的输出。如果我们调用 Crypto.HashPassword(string.Empty); 两次,我们也会得到不同的输出,因为它会在我们每次调用该函数时选择一个新的随机盐。

关于c# - 如何对 `string.Empty` 进行哈希处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20914157/

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