public function testPadding() { $texts = array(); $key = '0123456789ABCDEF0123456789ABCDEF'; $modes = array('ecb', 'cbc', 'cfb'); $pads = array(\Phalcon\Crypt::PADDING_ANSI_X_923, \Phalcon\Crypt::PADDING_PKCS7, \Phalcon\Crypt::PADDING_ISO_10126, \Phalcon\Crypt::PADDING_ISO_IEC_7816_4, \Phalcon\Crypt::PADDING_ZERO, \Phalcon\Crypt::PADDING_SPACE); for ($i = 1; $i < 128; ++$i) { $texts[] = str_repeat('A', $i); } $crypt = new \Phalcon\Crypt(); $crypt->setCipher(MCRYPT_RIJNDAEL_256)->setKey($key); foreach ($pads as $padding) { $crypt->setPadding($padding); foreach ($modes as $mode) { $crypt->setMode($mode); foreach ($texts as $text) { $encrypted = $crypt->encrypt($text); $actual = $crypt->decrypt($encrypted); $this->assertEquals($text, $actual); } } } }
<?php $crypt = new Phalcon\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypted = $crypt->encrypt($text, $key); echo $crypt->decrypt($encrypted, $key);
<?php //Create an instance $encryption = new Phalcon\Crypt(); //Use blowfish $encryption->setCipher('blowfish'); $key = 'le password'; $text = 'This is a secret text'; echo $encryption->encrypt($text, $key);
<?php //Create an instance $encryption = new Phalcon\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypted = $encryption->encrypt($text, $key); echo $encryption->decrypt($encrypted, $key);
<?php //Create an instance $crypt = new Phalcon\Crypt(); //Use blowfish $crypt->setCipher('blowfish'); $key = 'le password'; $text = 'This is a secret text'; echo $crypt->encrypt($text, $key);