We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

\Phalcon\Crypt() returns empty

$di->set('crypt', function () use ($config) { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CBC); $crypt->setCipher(MCRYPT_RIJNDAEL_128); $crypt->setKey($config->application->cryptSalt); return $crypt; }, true);

Can you suggest me why I am getting empty while I access $this->crypt



85.5k

you mean when you call

echo $this->crypt->encrypt('koko');
exit;

it's empty ?

your code:

  $di->set('crypt', function () use ($config) {
          $crypt = new \Phalcon\Crypt();
          $crypt->setMode(MCRYPTMODECBC);
          $crypt->setCipher(MCRYPTRIJNDAEL128);
          $crypt->setKey($config->application->cryptSalt);
          return $crypt;
    }, true);


13.2k
edited Oct '15

Thanks. It's showing value. But RESTcall returns empty Json for the below line.

$temp['img_path'] = $this->crypt->encrypt($image_url.$path); return $temp;



85.5k

my guess would be in the rest view stuff ?

echo json_encode($temp);exit; ?



13.2k

Hi,

No response. Still it shows empty. Is the problem of character set ?

Raja K



85.5k
edited Oct '15

php 5.ALL json is tricky with UTF-8 and chars, you should be careful.

From php7 they changed it, and it should work well



13.2k

Yes., Below code works.

 $enc = base64_encode($this->crypt->encrypt('999'));
                $temp['img'] = $enc;
                $dec = base64_decode($enc);
                $temp['reimg'] = trim($this->crypt->decrypt($dec));