PHP中的Keccak-256

时间:2017-06-25 00:34:04

标签: php cryptography sha keccak

我需要使用 Keccak-256 算法( NOT SHA3 )创建哈希值。

我正在运行 PHP 7.1 ,当我调用 hash_algos()时,会返回已注册的算法,但Keccak-256不存在。

支持的算法是:

[0] => md2
[1] => md4
[2] => md5
[3] => sha1
[4] => sha224
[5] => sha256
[6] => sha384
[7] => sha512/224
[8] => sha512/256
[9] => sha512
[10] => sha3-224
[11] => sha3-256
[12] => sha3-384
[13] => sha3-512
[14] => ripemd128
[15] => ripemd160
[16] => ripemd256
[17] => ripemd320
[18] => whirlpool
[19] => tiger128,3
[20] => tiger160,3
[21] => tiger192,3
[22] => tiger128,4
[23] => tiger160,4
[24] => tiger192,4
[25] => snefru
[26] => snefru256
[27] => gost
[28] => gost-crypto
[29] => adler32
[30] => crc32
[31] => crc32b
[32] => fnv132
[33] => fnv1a32
[34] => fnv164
[35] => fnv1a64
[36] => joaat
[37] => haval128,3
[38] => haval160,3
[39] => haval192,3
[40] => haval224,3
[41] => haval256,3
[42] => haval128,4
[43] => haval160,4
[44] => haval192,4
[45] => haval224,4
[46] => haval256,4
[47] => haval128,5
[48] => haval160,5
[49] => haval192,5
[50] => haval224,5
[51] => haval256,5

我在谷歌搜索了GITHUB,但我没有找到任何东西,谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

这个对我有用。

https://github.com/kornrunner/php-keccak

Keccak::hash('', 256); // 
c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

它与以太坊提供的web3.sh3()相对应。

return [
  ['Hello world!', '0xecd0e108a98e192af1d2c25055f4e3bed784b5c877204e73219a5203251feaab'],
  ["\n", '0x0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8'],
  ['1', '0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6'],
  ['-1', '0x798272c22de7de1bbb41d9d76b5240e67bb83e9ece1afeb940834536b3646693'],
  ['testing', '0x5f16f4c7f149ac4f9510d9cf8cf384038ad348b3bcdc01915f95de12df9d1b02'],
  ['', '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'],
];