To use this class, you need to have the mcrypt extension enabled. Example configuration: {{{ Session::config(array('default' => array( 'adapter' => 'Cookie', 'strategies' => array('Encrypt' => array('secret' => 'foobar')) ))); }}} By default, this strategy uses the AES algorithm in the CBC mode. This means that an initialization vector has to be generated and transported with the payload data. This is done transparently, but you may want to keep this in mind (the ECB mode doesn't require an itialization vector but is not recommended to use as it's insecure). You can override this defaults by passing a different cipher and/or mode to the config like this: {{{ Session::config(array('default' => array( 'adapter' => 'Cookie', 'strategies' => array('Encrypt' => array( 'cipher' => MCRYPT_RIJNDAEL_128, 'mode' => MCRYPT_MODE_ECB, // Don't use ECB when you don't have to! 'secret' => 'foobar' )) ))); }}} Please keep in mind that it is generally not a good idea to store sensitive information in cookies (or generally on the client side) and this class is no exception to the rule. It allows you to store client side data in a more secure way, but 100% security can't be achieved.
Inheritance: extends lithium\core\Object
 public function testDelete()
 {
     $encrypt = new Encrypt(array('secret' => $this->secret));
     $key = 'fookey';
     $value = 'barvalue';
     $result = $encrypt->write($value, array('class' => $this->mock, 'key' => $key));
     $this->assertTrue($result);
     $cookie = MockCookieSession::data();
     $result = $encrypt->read($key, array('class' => $this->mock, 'key' => $key));
     $this->assertEqual($value, $result);
     $result = $encrypt->delete($key, array('class' => $this->mock, 'key' => $key));
     $cookie = MockCookieSession::data();
     $this->assertTrue(empty($cookie['__encrypted']));
     $result = $encrypt->read($key, array('class' => $this->mock));
     $this->assertFalse($result);
 }
Example #2
0
 public function decrypt($encrypted)
 {
     return parent::_decrypt($encrypted);
 }