/** * Decodes and decrypts a single value. * * @param string $value The value to decode & decrypt. * @param string|false $encrypt The encryption cipher to use. * @return string Decoded value. */ protected function _decode($value, $encrypt) { if (!$encrypt) { return $this->_explode($value); } $this->_checkCipher($encrypt); $prefix = 'Q2FrZQ==.'; $value = base64_decode(substr($value, strlen($prefix))); if ($encrypt === 'rijndael') { $value = Security::rijndael($value, $this->_config['key'], 'decrypt'); } if ($encrypt === 'aes') { $value = Security::decrypt($value, $this->_config['key']); } return $this->_explode($value); }
/** * Decodes and decrypts a single value. * * @param string $value The value to decode & decrypt. * @return string Decoded value. */ protected function _decode($value) { $prefix = 'Q2FrZQ==.'; $pos = strpos($value, $prefix); if ($pos === false) { return $this->_explode($value); } $value = base64_decode(substr($value, strlen($prefix))); if ($this->_config['encryption'] === 'rijndael') { $plain = Security::rijndael($value, $this->_config['key'], 'decrypt'); } if ($this->_config['encryption'] === 'aes') { $plain = Security::decrypt($value, $this->_config['key']); } return $this->_explode($plain); }
/** * testRijndaelInvalidKey method * * @expectedException \InvalidArgumentException * @return void */ public function testRijndaelInvalidKey() { $txt = 'The quick brown fox jumped over the lazy dog.'; $key = 'too small'; Security::rijndael($txt, $key, 'encrypt'); }
/** * Decodes and decrypts a single value. * * @param string $value The value to decode & decrypt. * @param string|false $encrypt The encryption cipher to use. * @param string|null $key Used as the security salt if specified. * @return string Decoded value. */ protected function _decode($value, $encrypt, $key) { if (!$encrypt) { return $this->_explode($value); } $this->_checkCipher($encrypt); $prefix = 'Q2FrZQ==.'; $value = base64_decode(substr($value, strlen($prefix))); if ($key === null) { $key = $this->_getCookieEncryptionKey(); } if ($encrypt === 'rijndael') { $value = Security::rijndael($value, $key, 'decrypt'); } if ($encrypt === 'aes') { $value = Security::decrypt($value, $key); } return $this->_explode($value); }