How does BitConverter.ToInt64 handles a byte arry with 32 bytes (a 256 bit hash from SHA256Managed)

人走茶凉 提交于 2019-12-13 05:13:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9804265/how-does-bitconverter-toint64-handles-a-byte-arry-with-32-bytes-a-256-bit-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!