@ Марио: Спасибо за ответ.Это код, который у меня есть для шифрования.
class Cookie {
private $created;
private $userid;
private $version;
// mcrypt handle
private $td;
// mcrypt information
static $cipher = 'rijndael-256';
static $mode = 'ofb';
static $key = '$pxaWyXY67UIq*i&mNlFswBzyJkL7#1N';
// Cookie format information
static $cookiename = 'USERAUTH';
static $myversion = '1';
// When the cookie expires
static $expiration = '600';
// When to reissue the cookie
static $warning = '300';
static $glue = '|';
public function __construct($userid = false) {
$this->td = mcrypt_module_open($cipher, '', $mode, '');
if($this->userid) {
$this->userid = $userid;
} else {
if(array_key_exists(self::$cookiename, $_COOKIE)) {
$buffer = $this->_unpackage($_COOKIE[self::$cookiename]);
} else {
throw new AuthException("No Cookie");
}
}
}
public function _encrypt($plaintext) {
//$td = mcrypt_module_open (self::$cipher, '', self::$mode, '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MYCRYPT_RAND);
mcrypt_generic_init ($td, $plaintext);
$crypttext = mcrypt_generic($td, $plaintext);
mcrypt_generic_deinit ($td);
return $iv.$crypttext;
}
public function _decrypt($crypttext) {
//$td = mcrypt_module_open (self::$cipher, '', self::$mode, '');
$ivsize = mcrypt_enc_get_iv_size ($td);
$iv = substr ($crypt, 0, $ivsize);
$crypttext = substr ($crypttext, $ivsize);
$plaintext = "";
if($iv) {
mcrypt_generic_init($td, self::$key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
mcrypt_generic_deinit ($td);
}
return $plaintext;
}