Draco
Draco

Reputation: 460

Bcrypt encryption in Symfony2

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?

Upvotes: 2

Views: 871

Answers (1)

Gerry
Gerry

Reputation: 6012

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.

Upvotes: 4

Related Questions