Can I generate SHA1 in Perl or PHP?

Verotel requires some data to be hashed using the sha1_hex function. What it is? There is no information about this all over the Internet. They say that "SHA-1 hash" (hexadecimal output) is used. "Sha1 with hexadecimal output?

Here is one example that I cannot reproduce:

sha1_hex ("abc777X: description = some product description: priceAmount = 51.20: priceCurrency = EUR: shopID = 60678: version = 1")

= 04d87d2718767ea0bef259c436ec63e3cde05be2

+4
source share
5 answers
echo sha1('abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1'); 

Actually, sha1_hex has the name sha1() in php. Here is an example working on your input: http://codepad.org/9fLlr9VJ

+9
source
 $ 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 

SHA-1 hash produces 20-byte output. If you represent these 20 bytes in hexadecimal, you will get 40 characters.

+7
source

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 
+7
source
 $ php -r 'var_dump(sha1("abc777X:description=some description of product:priceAmount=51.20:priceCurrency=EUR:shopID=60678:version=1"));' string(40) "04d87d2718767ea0bef259c436ec63e3cde05be2" $ 

It works for me.

0
source

In PHP, the function is sha1 , not sha1_hex .

0
source

All Articles