将MD5或SHA1哈希码生成为长(64位) [英] Produce MD5 or SHA1 hash code to long (64 bits)

查看:657
本文介绍了将MD5或SHA1哈希码生成为长(64位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算一个字符串的哈希码并将其存储到一个'long'变量中。

MD5和SHA1产生的哈希码长度大于64位(MD5 - 128位,SHA1 - 160位)。

想法任何一个?



干杯, p>

Doron

解决方案

您可以截断散列并只使用前64个位。散列的强度会稍低一些,但前64位仍然极有可能是唯一的。



对于散列的大多数用法,这是一个常见的且完全可以接受的练习。

您也可以将整个散列存储为两个64位整数。


I need to compute a hash code of a string and store it into a 'long' variable.

MD5 and SHA1 produce hash codes which are longer than 64 bits (MD5 - 128 bits, SHA1 - 160 bit).

Ideas any one?

Cheers,

Doron

解决方案

You can truncate the hash and use just the first 64 bits. The hash will be somewhat less strong, but the first 64 bits are still extremely likely to be unique.

For most uses of a hash this is both a common and perfectly acceptable practice.

You can also store the complete hash in two 64-bit integers.

这篇关于将MD5或SHA1哈希码生成为长(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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