public function testNewApi() { $text = "testme"; $key = "frop"; $salt = sha1("saltgeneration"); $crypt = new ar_crypt($key, MCRYPT_RIJNDAEL_256, 1); $key = $crypt->pbkdf2($key, $salt); $crypt = new ar_crypt($key, MCRYPT_RIJNDAEL_256, 1); $encoded = $crypt->crypt($text); $decoded = $crypt->decrypt($encoded); $this->assertEquals($text, $decoded); }
function ldEncodeCookie($cookie) { global $AR; $data = json_encode($cookie); if (isset($AR->sessionCryptoKey)) { $key = base64_decode($AR->sessionCryptoKey); $crypto = new ar_crypt($key, MCRYPT_RIJNDAEL_256, 1); $encdata = $crypto->crypt($data); if ($encdata !== false) { $data = $encdata; } } return $data; }
protected function serialize($value, $path) { if ($value->failedDecrypt && $value->originalData) { $value = $value->originalData; return $value; } // Notice: When upgrading to a new crypto format, prepend the object data with a key of the crypto. This way you can be backwards compatible but new objects will be saved in the new crypto. if ($this->config['crypto'] instanceof \Closure) { $crypto = $this->config['crypto'](); // use the last crypto configured; $cryptoConfig = end($crypto); if (is_array($cryptoConfig['paths'])) { foreach ($cryptoConfig['paths'] as $cryptoPath) { if (strpos($path, $cryptoPath) === 0) { $value->ARcrypted = true; switch ($cryptoConfig['method']) { case 'ar_crypt': $key = base64_decode($cryptoConfig['key']); $crypto = new ar_crypt($key, $cryptoConfig['crypto'], 1); $cryptedValue = $crypto->crypt(serialize($value)); if ($cryptedValue !== false) { return $cryptoConfig['token'] . ":" . $cryptedValue; } break; default: break; } } } } } unset($value->ARcrypted); return serialize($value); }