dqprf0976 2015-06-03 15: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 15: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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度