简体   繁体   English

不同的php版本上不同的sha1校验和?

[英]different sha1 checksum on different php versions?

I run this script: 我运行这个脚本:

define('SECRET', "vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5");
echo sha1(SECRET . 'zcbkeyky' . 'aaa@bbb.com') . "\n";

Locally with PHP 5.3.2 (cli) it gives me: 3baa47e50394cd2dce236dcbf2f409fdb9010f2a 在本地使用PHP 5.3.2(cli)它给了我: 3baa47e50394cd2dce236dcbf2f409fdb9010f2a
On a remote machine with PHP 5.1.6 (cli) it gives: d1bcf4ea83e50593d3df19a8455a5f5cd32d63ef 在PHP 5.1.6(cli)的远程计算机上,它给出: d1bcf4ea83e50593d3df19a8455a5f5cd32d63ef

Why does the same calculation differ? 为什么相同的计算不同?

I'd say the problem is here: 我想问题就在这里:

define('SECRET', "vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5");
//                        ^^-- escape character

PHP manual says: PHP手册说:

\\x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation \\x[0-9A-Fa-f]{1,2}与正则表达式匹配的字符序列是十六进制表示的字符

Between PHP 5.2 and 5.3, apparently this was modified to also match \\X[0-9A-Fa-f]{1,2} (note the capital X at the beginning). 在PHP 5.2和5.3之间,显然这被修改为也匹配\\X[0-9A-Fa-f]{1,2} (注意开头的大写字母X)。 When running in PHP 5.3, you have (unknowingly?) a Carriage Return in your string. 在PHP 5.3中运行时,您(在不知不觉中?)字符串中的回车符。

Either a) replace the backslash with another character, or b) use single quotes when defining SECRET, and both versions will return the same hash (tried on 5.2.1 and 5.3.2). a)用另一个字符替换反斜杠,或b)在定义SECRET时使用单引号,两个版本将返回相同的散列(在5.2.1和5.3.2上尝试)。

Only thing I can think of is the encoding of the files/strings on each server? 我能想到的只是每台服务器上文件/字符串的编码?

My result is 3baa47e50394cd2dce236dcbf2f409fdb9010f2a (Locally) 我的结果是3baa47e50394cd2dce236dcbf2f409fdb9010f2a(本地)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM