加密密码FOSUserBundle


Encryption password FOSUserBundle

我有一个使用FOSUSerBundle管理用户的symfony项目,现在我需要通过Simple Rest Web Service访问数据库,注册中的加密是:Sha512,我如何获得与FOS相同的哈希结果我试过了:

hash('sha512',($salt.$password));

hash('sha512',($password.$salt));

但是它不起作用!有什么建议吗?

根据为FOSUserBundle编码密码的thing class,您可以了解Symfony是如何进行加密的

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php

所以你会得到这样的东西:

$password = 'toto';
$salt = '1234';
$salted = $password.'{'.$salt.'}';
$digest = hash('sha512', $salted, true);
for ($i=1; $i<5000; $i++) {
    $digest = hash('sha512', $digest.$salted, true);
}
$encodedPassword = base64_encode($digest);