Skip to content

Commit

Permalink
Minor changes to the CookieCryptTrait, doc block & property
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Mar 1, 2017
1 parent 9dfdc20 commit 8065bc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Http/Cookie/Cookie.php
Expand Up @@ -381,6 +381,7 @@ public function read($path = null)
* Throws a \RuntimeException if the cookie value was not expanded
*
* @throws \RuntimeException
* @return void
*/
protected function _isExpanded()
{
Expand Down
13 changes: 9 additions & 4 deletions src/Http/Cookie/CookieCryptTrait.php
Expand Up @@ -48,6 +48,13 @@ trait CookieCryptTrait
*/
protected $encryptionKey = '';

/**
* Prefix of the encrypted string
*
* @var string
*/
protected $encryptedStringPrefix = 'Q2FrZQ==.';

/**
* Sets the encryption cipher
*
Expand Down Expand Up @@ -124,15 +131,14 @@ protected function _encrypt($value)
}

$encrypt = $this->encryptionCipher;
$prefix = 'Q2FrZQ==.';
$cipher = null;
$key = $this->getEncryptionKey();

if ($encrypt === 'aes') {
$cipher = Security::encrypt($value, $key);
}

return $prefix . base64_encode($cipher);
return $this->encryptedStringPrefix . base64_encode($cipher);
}

/**
Expand Down Expand Up @@ -185,11 +191,10 @@ protected function _decode($value)
return $this->_expand($value);
}

$prefix = 'Q2FrZQ==.';
$key = $this->getEncryptionKey();
$encrypt = $this->encryptionCipher;

$value = base64_decode(substr($value, strlen($prefix)));
$value = base64_decode(substr($value, strlen($this->encryptedStringPrefix)));

if ($encrypt === 'aes') {
$value = Security::decrypt($value, $key);
Expand Down

0 comments on commit 8065bc7

Please sign in to comment.