如何在phalcon中解密哈希安全性



保存crypt哈希安全:

$usuario = new User();
$usuario->password = $this->security->hash($this->request->getPost("pass"));
if (!$usuario->save()) {
    foreach ($usuario->getMessages() as $message) {
    $this->flash->error($message);
    }
    $this->dispatcher->forward([
        'controller' => "usuario",
        'action' => 'new'
    ]);
    return;
}

现在,如何解密哈希安全以发送我的表格:

$usuario = User::findFirstByid($iduser);
$this->tag->setDefault("pass", $this->encryption->decrypt($usuario->password));

我有一个:注意:访问...

中的未定义属性加密

正如@Juri所说的哈希只是一种方式。但是,您可以使用encryptBase64()是两种方式,可以将其解码。不要将其用于密码,将其用于某些数据,您需要将其传递给某人并将其读回去,例如API令牌等。

这是如何设置它的方法:

$di->setShared('crypt', function () use ($config) {
    $crypt = new PhalconCrypt();
    $crypt->setKey('i$4^&/:%2@k50ROQ<@{(e=*!<7u|rI~0');
    return $crypt;
});

我创建的辅助功能,但是您可以直接使用它:

...
...
private static $cryptKey = 'i$4^&/:%2@k50ROQ<@{(e=*!<7u|rI~0';
/**
 *  Generate url safe encoded string
 *
 *  @param string $string string to be encoded
 *  @return encoded string
 */
public static function encodeString($string)
{
    $crypt = new PhalconCrypt();
    return $crypt->encryptBase64($string, self::$cryptKey, true);
}
/**
 *  Decode string generated with Common::encodeString()
 *
 *  @param string $string Encoded string
 *  @return decoded string
 */
public static function decodeString($string)
{
    $crypt = new PhalconCrypt();
    return $crypt->decryptBase64($string, self::$cryptKey, true);
}

最新更新