【发布时间】:2012-01-17 00:10:07
【问题描述】:
这个问题类似于: How to get a 64 bit integer hash from a string in PHP?
我有这个 JAVA 功能。我想在 PHP 中具有相同的功能。谢谢
/**
* returns the first 64 bits of the md5 digest as a long
*/
public static long get64BitMD5(String text) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(text.getBytes(UTF_8));
byte [] digest = md.digest();
long ret = 0;
for (int i = 0; i < 8; i++)
ret = (ret<<8)|(((long)digest[i])&0xFFl);
return ret;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
【问题讨论】: