Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 SHA256Managed 生成 256 位哈希,我想将它们存储在 sql server 上。BitConverter.ToInt64 对此有多好?它会忽略额外的字节吗?在转换为 int64 之前,我应该做一些处理来减少字节数组吗?
仅使用BitConverter.ToInt648 个字节来生成值,因此数组中的任何额外字节都将被忽略。
BitConverter.ToInt64
如果要存储完整的 256 位哈希,则需要使用不同的数据类型。
如果您只想使用哈希的前 64 位,那通常就可以了。整个哈希码应该受到计算哈希的每个字节的影响,因此只有一部分哈希本身仍然会产生良好的哈希。哈希冲突的风险自然会更大,但 64 位通常足以使它们足够稀有。