dqprf0976 2015-06-03 07:09 采纳率: 100%
浏览 87
已采纳

Symfony2中的Bcrypt加密

I need to encrypt a string in Symfony using bcrypt. The string is not a password it's an API Key that will be saved in database as bcrypt hash. To do that I am doing simply

$key = 'superSecretKey';
$options = array('cost' => 12);
$hash = password_hash($key, PASSWORD_BCRYPT, $options)

The problem is that password_hash() works only on PHP 5 >= 5.5.0 and I still want to preserve compatibility with PHP 5.4

Is there a "Symfony way" of encrypting string so in case of PHP version below 5.5 it will use ircmaxell/password_compat like Symfony security is doing?

  • 写回答

1条回答 默认 最新

  • douken0530 2015-06-03 07:29
    关注

    ircmaxell/password_compat is a polyfill library. You can just add it to your dependencies and call the password_hash() function without worrying about the PHP version. For PHP 5.5+ it will use the native PHP version, for lower versions it will resort to the library.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部