我如何正确使用php sha1十六进制?

时间:2012-08-11 00:49:32

标签: php sha1

如何通过php编写此代码并获得类似的结果?

为SHA calc构建MSG

 MSG_TXT = "8F"+"08"+"1234567890123470"+"08"+"1234567890123470"+"0743210987654321"+"08"
 Convert MSG_TXT to MSG_BIN [] = {$8F,$08,$12,$34,$56, ..... $65,$43,$21,$08}
 SHA-1(MSG_BIN[]) = 9E667331662BE10D78D56F75D6899F764212C5C1

这段代码在delphi中工作,但它在php

中没有起到类似的效果

1 个答案:

答案 0 :(得分:0)

试试这个:

// your string
$txt = "8F"."08"."1234567890123470"."08"."1234567890123470"."0743210987654321"."08";
// convert to binary string
$txt = pack('H*', $txt);
// print sha1
echo sha1($txt, false);