1. Encryption and Decryption class
1 class Mcrypt 2 {3/** 4 * Decrypt 5 * 6 * @param string $encryptedText encrypted string 7 * @param str ing $key key 8 * @return String 9/A public static function _decrypt ($encryptedText, $key = null) 11 {$key = $key = = null?
Config::get (' Secret_key '): $key;
$cryptText = Base64_decode ($encryptedText);
$ivSize = Mcrypt_get_iv_size (mcrypt_rijndael_256, MCRYPT_MODE_ECB);
$iv = Mcrypt_create_iv ($ivSize, Mcrypt_rand);
$decryptText = Mcrypt_decrypt (mcrypt_rijndael_256, $key, $cryptText, MCRYPT_MODE_ECB, $IV);
Return trim ($decryptText); 18} 19 20/** 21 * Encryption * * @param string $plainText unencrypted string @param string $key Key/Num public static function _encrypt ($plainText, $key = null) $key = $key = = NULL ?
Config::get (' Secret_key '): $key; $ivSize = Mcrypt_get_iv_size (mcrypt_rijndael_256, Mcrypt_mode_ECB);
$iv = Mcrypt_create_iv ($ivSize, Mcrypt_rand);
$encryptText = Mcrypt_encrypt (mcrypt_rijndael_256, $key, $plainText, MCRYPT_MODE_ECB, $IV);
Return Trim (Base64_encode ($encryptText)); 33} 34}
2.cookie Encryption and Decryption class
1 <?php 2 class Cookie extends Mcrypt 3 {4/** 5 * Delete Cookie 6 * 7 * @param array $args 8 * @return Boolean 9/A public static function del ($args) one {$name = $args [' name ']; 13 $domain = Isset ($args [' domain '])?
$args [' domain ']: null; return Isset ($_cookie[$name])?
Setcookie ($name, ', Time ()-86400, '/', $domain): true; 15} 16 17/** 18 * Get the value of the specified cookie * * @param string $name/public stat IC function Get ($name) {return isset ($_cookie[$name])? Parent::_decrypt ($_cookie[$name]): null; 25 26 27/** 28 * Set Cookie * * @param array $args * @return Boolean 32/33 The public static function set ($args) is $name = $args [' name ']; $value = Parent::_encrypt ($args
[' value ']); Panax Notoginseng $expire = isset ($args [' expire '])?
$args [' expire ']: null; $path =Isset ($args [' path '])?
$args [' Path ']: '/'; $domain = Isset ($args [' domain '])?
$args [' domain ']: null; $secure = Isset ($args [' secure '])?
$args [' secure ']: 0;
Return Setcookie ($name, $value, $expire, $path, $domain, $secure); 42} 43}