Will PHP's sha1() and MySQL's SHA() give the same result?
If no salt is used, will they be the same?开发者_JAVA百科
Yes. The sha1 algorithm always produces the same value for the same input; that's the whole point of a hashing algorithm. They also both return a 40-character lowercase hex dump by default.
Both claim to implement RFC 3174. Thus, they produce the same result (otherwise there is a bug in the implementation).
Of course.
Note that the algorithm defines 160
bits and the script language implementations can return their hexadecimal representation as a string instead. The register and the dashes of the hexadecimal representation may be different in some implementations.
However, MySQL
and PHP
both return in lower case and no dashes.
Yes.
If You will run into case where these are not equal (like i just now had) then most likely You either got something wrong with Your method which uses the hash or incorrect database state where You for example updated few fields but forgot to change the corresponding hash.
精彩评论