示例#1
0
 public function testEncryptDecrypt()
 {
     $key = 'foobar';
     $data = 'very secret';
     $iv = Crypt::getiv();
     $encrypted = Crypt::encrypt($data, $key, $iv);
     $this->assertNotEquals($data, $encrypted);
     $decrypted = Crypt::decrypt($encrypted, $key, $iv);
     $this->assertEquals($data, $decrypted);
 }
示例#2
0
文件: storage.php 项目: photon/photon
 /**
  * Given the response object, save the data.
  *
  * Even if your storage is not cookie based, if you are using a
  * cookie to store the session id, you must imperatively set the
  * cookie to keep track of the session id. 
  *
  * @required public function commit($response) 
  */
 public function commit($response)
 {
     $timeout = time() + 365 * 24 * 3600;
     if (0 === strlen($this->iv)) {
         $this->iv = Crypt::getiv();
         $response->COOKIE->setCookie('scsiv', $this->iv, $timeout);
     }
     foreach ($this->cache as $name => $val) {
         $val = Crypt::encrypt($val, Conf::f('secret_key'), $this->iv);
         $response->COOKIE->setCookie('scs-' . $name, $val, $timeout);
     }
     foreach ($this->deleted as $name => $val) {
         $response->COOKIE->delCookie('scs-' . $name);
     }
     return $this->getNewKey(json_encode($response->headers));
 }