此問題類似於: How to get a 64 bit integer hash from a string in PHP?在PHP中將md5摘要的前64位計算爲整數?
我有這個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);
}
}
64位PHP確實有64位有符號整數,而不是64位無符號整數...但它是可以計算的64位字節流 – 2012-01-17 00:30:46
@MarkBaker:這是[瑣碎]( http://www.php.net/manual/en/function.pack.php)將'md5'的十六進制輸出轉換爲原始字節,如果這是OP想要的。唯一的問題是他們沒有告訴。 – Jon 2012-01-17 00:34:05