支持中文的php加密解密类代码
2015-01-24信息快讯网
支持中文的php加密解密类代码,需要的朋友可以参考下。
php代码类:<?php /** * Copyright (c) 2011 - 01 XatuDream * XatuDream All Rights Reserved. * Support:185390516.qzone.qq.com * QQ:185390516 * Author:Lau Version:1.01 * Date:2010-08-12 09:28:32 */ ! defined ( 'WORKSPACE' ) && exit ( "Access Denied !" ); class MD5Crypt { /** * Enter description here ... * @param unknown_type $str * @return string */ public final static function mdsha($str) { $code = substr ( md5 ( $str ), 10 ); $code .= substr ( sha1 ( $str ), 0, 28 ); $code .= substr ( md5 ( $str ), 0, 22 ); $code .= substr ( sha1 ( $str ), 16 ) . md5 ( $str ); return self::chkToken () ? $code : null; } /** * Enter description here ... * @param unknown_type $param */ private final static function chkToken() { return true; } /** * Enter description here ... * @param unknown_type $txt * @param unknown_type $encrypt_key * @return Ambigous <string, boolean> */ private final static function keyED($txt, $encrypt_key) { $encrypt_key = md5 ( $encrypt_key ); $ctr = 0; $tmp = ""; for($i = 0; $i < strlen ( $txt ); $i ++) { if ($ctr == strlen ( $encrypt_key )) $ctr = 0; $tmp .= substr ( $txt, $i, 1 ) ^ substr ( $encrypt_key, $ctr, 1 ); $ctr ++; } return $tmp; } /** * Enter description here ... * @param unknown_type $txt * @param unknown_type $key * @return string */ public final static function Encrypt($txt, $key) { srand ( ( double ) microtime () * 1000000 ); $encrypt_key = md5 ( rand ( 0, 32000 ) ); $ctr = 0; $tmp = ""; for($i = 0; $i < strlen ( $txt ); $i ++) { if ($ctr == strlen ( $encrypt_key )) $ctr = 0; $tmp .= substr ( $encrypt_key, $ctr, 1 ) . (substr ( $txt, $i, 1 ) ^ substr ( $encrypt_key, $ctr, 1 )); $ctr ++; } $_code = md5 ( $encrypt_key ) . base64_encode ( self::keyED ( $tmp, $key ) ) . md5 ( $encrypt_key . $key ); return self::chkToken () ? $_code : null; } /** * Enter description here ... * @param unknown_type $txt * @param unknown_type $key * @return Ambigous <string, boolean> */ public final static function Decrypt($txt, $key) { $txt = self::keyED ( base64_decode ( substr ( $txt, 32, - 32 ) ), $key ); $tmp = ""; for($i = 0; $i < strlen ( $txt ); $i ++) { $md5 = substr ( $txt, $i, 1 ); $i ++; $tmp .= (substr ( $txt, $i, 1 ) ^ $md5); } return self::chkToken () ? $tmp : null; } /** * Enter description here ... * @var unknown_type */ private static $_key = 'lau'; } ?>
使用方法:
<?php //Code Start /** * Copyright (c) 2011 XatuDream * XatuDream All Rights Reserved. * Support:185390516.qzone.qq.com * QQ:185390516 * Author:LoveCrystal Version:1.01 * Date:2011-9-2 04:00:37 */ define ( 'WORKSPACE', '.' . DIRECTORY_SEPARATOR ); header ( "Content-Type: text/html; charset=utf-8" ); include_once 'Core/Library/MD5Crypt.class.php'; $a = MD5Crypt::Encrypt ( "A", 100 ); echo "EnCode:" . $a, "<br />"; echo "DeCode:" . MD5Crypt::Decrypt ( $a, 100 ); ?>
深入php函数file_get_contents超时处理的方法详解
详解PHP内置访问资源的超时时间 time_out file_get_contents read_file
PHP CLI模式下的多进程应用分析
基于php-fpm 参数的深入理解
php-cli简介(不会Shell语言一样用Shell)
PHP在线生成二维码代码(google api)
基于Discuz security.inc.php代码的深入分析
PHP代码保护--Zend Guard的使用详解
优化PHP代码技巧的小结
php源代码安装常见错误与解决办法分享
php操作SVN版本服务器类代码
php UBB 解析实现代码
PHP高自定义性安全验证码代码
php中XMLHttpRequest(Ajax)不能设置自定义的Referer的解决方法
php 团购折扣计算公式
php中$_REQUEST、$_POST、$_GET的区别和联系小结
打造超酷的PHP数据饼图效果实现代码
php中一个完整表单处理实现代码
PHP操作文件类的函数代码(文件和文件夹创建,复制,移动和删除)