佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1608|回复: 1

求助PHP Cookie 加密 帮忙看看到底是什么问题

[复制链接]
发表于 12-5-2010 11:50 PM | 显示全部楼层 |阅读模式
我花了整天 都解决不到 akiz, 求求 各位大大 帮我 看看下 。 请指点 先谢啦。

2 个 PHP 文件

EncDec.php

  1. <?php
  2.         class EncryptionsGKL{
  3.                
  4.                 /*
  5.                 Simple Encrypt and Decrypt
  6.                 Written By Goh Keat Liang
  7.                 v0.1 initial release
  8.                 GPL v2.0 from community, to community
  9.                 */
  10.                
  11.                
  12.                 //settings for the encryption
  13.                 //private $encryption_mode = MCRYPT_MODE_ECB/CFB;
  14.                 private $encryption_mode = MCRYPT_MODE_CFB;
  15.                 private $cipher_algorithm = MCRYPT_RIJNDAEL_256;
  16.                 private $word = "genesis6";
  17.                 private $key = "";
  18.                 private $ivs = "";
  19.                 private $iv = "";
  20.                
  21.                
  22.                 function __construct(){
  23.                         $this->key = $this->hash($word);
  24.                         //echo $this->key;
  25.                         //create the cipher vector for the cookie
  26.                         //can tweek the vector size
  27.                         $this->ivs = mcrypt_get_iv_size($this->cipher_algorithm, $this->encryption_mode);
  28.                         $this->iv = mcrypt_create_iv($this->ivs, MCRYPT_DEV_URANDOM);
  29.                 }
  30.                
  31.                
  32.                 private function hash($word){
  33.                         return md5($word);
  34.                 }
  35.                        
  36.                 public function descrypt($text_to_decrypt){
  37.                         return mcrypt_decrypt($this->cipher_algorithm, $this->key, hexdec($text_to_decrypt), $this->encryption_mode, $this->iv);
  38.                 }
  39.                
  40.                 public function encrypt($text_to_encrypt){

  41.                         return mcrypt_encrypt($this->cipher_algorithm, $this->key, $text_to_encrypt, $this->encryption_mode, $this->iv);
  42.                 }

  43.                
  44.                
  45.         }
  46.        
  47.         /*$testE = new EncryptionsGKL();
  48.         echo $cipher_ = $testE->encrypt("keatliang");
  49.         echo $testE->descrypt($cipher_);*/
  50. ?>
复制代码


cookie.php

  1. <?
  2.         /*
  3.                 Simple Cookie Lib with simple Encryption
  4.                 Written by Goh Keat Liang
  5.                 v0.1 initial release
  6.                 GPL v2.0 from community, to community
  7.         */
  8.         include 'EncDec.php';
  9.        
  10.         //add a list of cookie you wanted
  11.         class COOKIE{
  12.                 public static $USER_ID = "UID";
  13.         }
  14.        
  15.         class CookieGKL extends EncryptionsGKL{
  16.                
  17.                 private $numExpiredTime = "";
  18.                 private $strCookiePath = "";
  19.                 private $strDomain = "";
  20.                
  21.                
  22.                 function __construct($numExpiredTime,$strCookiePath,$strDomain){
  23.                         parent::__construct();
  24.                         $this->numExpiredTime = $numExpiredTime;
  25.                         $this->strCookiePath = $strCookiePath;
  26.                         $this->strDomain = $strDomain;

  27.                 }
  28.                
  29.                
  30.                 public function setCookie($cookieName,$cookieValue){
  31.                         $cookieValue = $this->encrypt($cookieValue);
  32.                         setcookie($cookieName,
  33.                                                 $cookieValue,
  34.                                                 $this->numExpiredTime,
  35.                                                 $this->strCookiePath,
  36.                                                 $this->strDomain
  37.                                                 );

  38.                 }
  39.                
  40.                 public function getCookie($cookieName){
  41.                         $cookieCryptedValue = $_COOKIE[$cookieName];
  42.                         return $this->descrypt($cookieCryptedValue);
  43.                 }
  44.                
  45.                 public function destroyCookies(){
  46.                 }
  47.                
  48.                 public function removeCookie(){
  49.                 }
  50.         }
  51.        
  52.         $testC = new CookieGKL(time()+3600,"/","genesissix.com",1);
  53.        
  54.         $testC->setCookie(COOKIE::$USER_ID, 'keatliang');
  55.         echo $testC->getCookie(COOKIE::$USER_ID);
  56. ?>
复制代码
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 13-5-2010 01:38 AM | 显示全部楼层
研究到了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-11-2025 07:42 AM , Processed in 0.104778 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表