简体   繁体   English

我可以在 Perl 或 PHP 中生成 SHA1 吗?

[英]Can I generate a SHA1 in Perl or PHP?

Verotel requires some data to be hashed with sha1_hex function. Verotel 需要使用 sha1_hex function 对一些数据进行哈希处理。 What exactly is it?它到底是什么? No info about it in the whole internet.在整个互联网上没有关于它的信息。 They say "SHA-1 hash is used (hexadecimal output)".他们说“使用了 SHA-1 hash(十六进制输出)”。 Sha1 with hex output?带有六角形 output 的 Sha1?

Heres one example which I can't seem to reproduce:这是一个我似乎无法重现的例子:

sha1_hex("abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1") sha1_hex("abc777X:description=一些产品描述:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1")

= 04d87d2718767ea0bef259c436ec63e3cde05be2 = 04d87d2718767ea0bef259c436ec63e3cde05be2

echo sha1('abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1');

Actually, that sha1_hex is named sha1() in php.实际上,该sha1_hex在 php 中被命名为sha1() Here is an example, working on your input: http://codepad.org/9fLlr9VJ这是一个示例,处理您的输入: http://codepad.org/9fLlr9VJ

$ perl -e 'use Digest::SHA qw(sha1_hex); print sha1_hex("abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1")'
04d87d2718767ea0bef259c436ec63e3cde05be2

The SHA-1 hash produces a 20 byte output. SHA-1 hash产生一个 20 字节的 output。 If you represent those 20 bytes in hexadecimal, you get 40 characters.如果你用十六进制表示这 20 个字节,你会得到 40 个字符。

For Perl: Digest::SHA (updated from Digest::SHA1).对于 Perl: Digest::SHA (从 Digest::SHA1 更新)。

perl -MDigest::SHA=sha1_hex -le'print sha1_hex("abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1")'
04d87d2718767ea0bef259c436ec63e3cde05be2
$ php -r 'var_dump(sha1("abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1"));'
string(40) "04d87d2718767ea0bef259c436ec63e3cde05be2"
$

Works for me.为我工作。

In PHP, the function is sha1 , not sha1_hex .在 PHP 中,function 是sha1 ,而不是sha1_hex

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

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