php实现cookie加密解密

1.加密解密类

 

 1 class Mcrypt
 2 {
 3     /**
 4      * 解密
 5      * 
 6      * @param string $encryptedText 已加密字符串
 7      * @param string $key  密钥
 8      * @return string
 9      */
10     public static function _decrypt($encryptedText,$key = null)
11     {
12         $key = $key === null ? Config::get('secret_key') : $key;
13         $cryptText = base64_decode($encryptedText);
14         $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
15         $iv = mcrypt_create_iv($ivSize,1)"> MCRYPT_RAND);
16         $decryptText = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,1)">$key,1)">$cryptText,MCRYPT_MODE_ECB,1)">$iv17         return trim($decryptText18     }
19  
20     21      * 加密
22      *
23      * @param string $plainText 未加密字符串 
24      * @param string $key        密钥
25      26     function _encrypt($plainText,1)">27 28         29         30         31         $encryptText = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,1)">32         trim(base64_encode($encryptText));
33 34 }

 

 

2.cookie加密解密类

 

 1 <?PHP
class Cookie extends 3  4          * 删除cookie
     * @param array $args
     * @return boolean
function del($args$name = $args['name'];
$domain = isset($args['domain']) ? $args['domain'] : 14         $_COOKIE[$name]) ? setcookie($name,'',1)">time() - 86400,'/',1)">$domain) : true15 16      
17          * 得到指定cookie的值
19 20      * @param string $name
21      22     function get($name24         $name]) ? parent::_decrypt($name]) : 25 26      
27     28      * 设置cookie
29 30 31 32      33     function set(34 35         36         $value= parent::_encrypt($args['value']);
37         $expire = $args['expire']) ? $args['expire'] : 38         $path = $args['path']) ? $args['path'] : '/'39         40         $secure = $args['secure']) ? $args['secure'] : 041         $value,1)">$expire,1)">$path,1)">$domain,1)">$secure42 43 }

 

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...