php实现一个简单的加密解密处理类
2016-02-18 00:00
627 查看
class SysCrypt { private $crypt_key; // 构造函数 public function __construct($crypt_key) { $this -> crypt_key = $crypt_key; } public function php_encrypt($txt) { srand((double)microtime() * 1000000); $encrypt_key = md5(rand(0,32000)); $ctr = 0; $tmp = ''; for($i = 0;$i<strlen($txt);$i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $encrypt_key[$ctr].($txt[$i]^$encrypt_key[$ctr++]); } return base64_encode(self::__key($tmp,$this -> crypt_key)); } public function php_decrypt($txt) { $txt = self::__key(base64_decode($txt),$this -> crypt_key); $tmp = ''; for($i = 0;$i < strlen($txt); $i++) { $md5 = $txt[$i]; $tmp .= $txt[++$i] ^ $md5; } return $tmp; } private function __key($txt,$encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } public function __destruct() { $this -> crypt_key = null; } } $sc = new SysCrypt('phpwms'); $text = '110'; print($sc -> php_encrypt($text)); print('<br>'); print($sc -> php_decrypt($sc -> php_encrypt($text)));
相关文章推荐
- php图片加水印, 生成缩略图
- php实现身份证号码检查类
- php zip压缩文件
- php zip解压文件
- php获取中文字符拼音首字母
- PHP zeroMq的简单例子
- php编译安装
- PHP——0126最初
- phpmyadmin登录不上,修改数据库密码
- xampp设置开机启动
- PHP——动态随机数
- PHP——投票
- phpmyadmin导入大文件
- PHP——内测:联系人管理
- PHP中json_encode后,在json字符串中依然显示中文的解决方案
- Windows下PHP配置成功后phpinfo中找不到mysql
- PHP PDO千万行数据导出
- php 自定义错误处理器 与 自定义异常处理器
- php 中用户触发错误与记录错误日志及异常处理
- ntp服务器被反射放大攻击的处理方法