PHP 的 SHA-512 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1966154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:28:55  来源:igfitidea点击:

SHA-512 library for PHP

phpsha2

提问by RKh

I am searching for any crypto library that provides SHA-512 hash. Googling around I found some but SHA-512 is absent.

我正在寻找任何提供 SHA-512 哈希的加密库。谷歌搜索我发现了一些,但没有 SHA-512。

Please suggest.

请建议。

回答by Pascal MARTIN

If you are using PHP >= 5.3, the function openssl_digestshould do the trick :

如果您使用的是 PHP >= 5.3,则该函数openssl_digest应该可以解决问题:

echo openssl_digest('glop', 'sha512');

gives me this output (splitted in two lines to get better readibility):

给我这个输出(分成两行以获得更好的可读性)

416b1861951170e1f6eb6543b0dd3d4f1994ce8da7cd82061513d3ddd1dd81111
f4ada5caf6421f1d17425c6f29bdb4a95cf84df9eda4164f5a762acbb490a68

(And you can use openssl_get_md_methodsto get the list of available digest methods)

(您可以使用openssl_get_md_methods来获取可用摘要方法的列表)


And with PHP 5.1 or 5.2, you have the hashfunction :


在 PHP 5.1 或 5.2 中,您拥有以下hash功能:

echo hash('sha512', 'glop');

gives me the same output (splitted, too):

给我相同的输出(也分开)

416b1861951170e1f6eb6543b0dd3d4f1994ce8da7cd82061513d3ddd1dd81111
f4ada5caf6421f1d17425c6f29bdb4a95cf84df9eda4164f5a762acbb490a68

And, here, to know the list of available digest methods, you can use hash_algos

而且,在这里,要了解可用摘要方法的列表,您可以使用 hash_algos

回答by Nick Presta

In PHP 5 >= 5.1.2, PECL hash >= 1.1:

在 PHP 5 >= 5.1.2 中,PECL 哈希 >= 1.1:

hash('sha512', someStr);

See hash()for more information.
To see all hash algorithms available to you, try:

有关详细信息,请参阅hash()
要查看所有可用的哈希算法,请尝试:

print_r(hash_algos());