\Phalcon\Crypt() returns empty

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

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



64.3k

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);


3.6k
edited Oct '15

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

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



64.3k

my guess would be in the rest view stuff ?

echo json_encode($temp);exit; ?



3.6k

Hi,

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

Raja K



64.3k
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



3.6k

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));