开发者

Can I generate a SHA1 in Perl or PHP?

Verotel requires some data to be hashed with sha1_hex function. What exactly is it? No info about it in the whole internet. They say "SHA-1 hash is used (hexadecimal output)". Sha1 with hex output?

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")

= 04d87d2718767ea0bef259c436ec63e3开发者_C百科cde05be2


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. Here is an example, working on your input: 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. If you represent those 20 bytes in hexadecimal, you get 40 characters.


For Perl: Digest::SHA (updated from 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜