BitConverter.ToInt64如何处理32字节的字节(来自SHA256Managed的256位散列) [英] How does BitConverter.ToInt64 handles a byte arry with 32 bytes (a 256 bit hash from SHA256Managed)

查看:418
本文介绍了BitConverter.ToInt64如何处理32字节的字节(来自SHA256Managed的256位散列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SHA256Managed生成256位散列,我想将它们存储在sql服务器上。 BitConverter.ToInt64对此有多好?它会忽略额外的字节吗?在转换为int64之前,我应该做一些处理以减少字节数组吗?

解决方案 BitConverter.ToInt64 仅使用8个字节来产生该值,因此数组中的任何额外字节都将被忽略。



如果要存储完整的256位散列,你需要使用不同的数据类型。



如果你只想使用散列的前64位,那通常很好。整个哈希码应该受到您计算哈希值的每个字节的影响,因此只有一部分哈希值本身仍然会生成一个好的哈希值。散列冲突自然会有更大的风险,但通常64位通常足够稀少。


I'm using SHA256Managed to generate 256 bit hashs and I would like to store them on sql server. How good is BitConverter.ToInt64 for this? Does it ignore the extra bytes? Should I do some processing to reduce the byte array before converting to int64?

解决方案

The BitConverter.ToInt64 only uses 8 bytes to produce the value, so any extra bytes in the array are ignored.

If you want to store the complete 256 bit hash, you need to use a different data type.

If you just want to use only the first 64 bits of the hash, that is usually just fine. The entire hash code should be affected by each byte that you calculated the hash for, so only a part of the hash still produces a good hash in itself. There will naturally be a larger risk for a hash collision, but 64 bits is usually enough to make them rare enough.

这篇关于BitConverter.ToInt64如何处理32字节的字节(来自SHA256Managed的256位散列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆