@@ 84-108 (lines=25) @@ | ||
81 | * |
|
82 | * @throws \Comodojo\Exception\CookieException |
|
83 | */ |
|
84 | public function setValue($value, $serialize = true) { |
|
85 | ||
86 | if ( !is_scalar($value) AND $serialize === false ) throw new CookieException("Cannot set non-scalar value without serialization"); |
|
87 | ||
88 | if ( $serialize === true ) $value = serialize($value); |
|
89 | ||
90 | $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB); |
|
91 | ||
92 | $cipher->setKeyLength(256); |
|
93 | ||
94 | $cipher->setKey(self::EncryptedKey($this->key)); |
|
95 | ||
96 | // added base64 encoding to avoid problems with binary data |
|
97 | ||
98 | $encrypted_value = $cipher->encrypt($value); |
|
99 | ||
100 | $cookie_value = base64_encode($encrypted_value); |
|
101 | ||
102 | if ( strlen($cookie_value) > $this->max_cookie_size ) throw new CookieException("Cookie size larger than 4KB"); |
|
103 | ||
104 | $this->value = $cookie_value; |
|
105 | ||
106 | return $this; |
|
107 | ||
108 | } |
|
109 | ||
110 | /** |
|
111 | * Get cookie content |
@@ 84-108 (lines=25) @@ | ||
81 | * |
|
82 | * @throws \Comodojo\Exception\CookieException |
|
83 | */ |
|
84 | public function setValue($value, $serialize = true) { |
|
85 | ||
86 | if ( !is_scalar($value) AND $serialize === false ) throw new CookieException("Cannot set non-scalar value without serialization"); |
|
87 | ||
88 | if ( $serialize === true ) $value = serialize($value); |
|
89 | ||
90 | $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB); |
|
91 | ||
92 | $cipher->setKeyLength(256); |
|
93 | ||
94 | $cipher->setKey(self::clientSpecificKey($this->key)); |
|
95 | ||
96 | // added base64 encoding to avoid problems with binary data |
|
97 | ||
98 | $encrypted_value = $cipher->encrypt($value); |
|
99 | ||
100 | $cookie_value = base64_encode($encrypted_value); |
|
101 | ||
102 | if ( strlen($cookie_value) > $this->max_cookie_size ) throw new CookieException("Cookie size larger than 4KB"); |
|
103 | ||
104 | $this->value = $cookie_value; |
|
105 | ||
106 | return $this; |
|
107 | ||
108 | } |
|
109 | ||
110 | /** |
|
111 | * Get cookie content |