我用什么:
爪哇:
public String sha1(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
结果:
java: System.out.println(sha1("foobar123dsadn23u1wdqqwdyxdasd"));
php: echo sha1('foobar123dsadn23u1wdqqwdyxdasd');
php: d8033103e9aaf67af13a4b45534b2d0f6d8dfded
java: d83313e9aaf67af13a4b45534b2df6d8dfded
为什么两个哈希不一样?