支持中文的php加密解密类代码

PHP代码类:
<div class="codetitle"><a style="CURSOR: pointer" data="68172" class="copybut" id="copybut68172" onclick="doCopy('code68172')"> 代码如下:

<div class="codebody" id="code68172">
<?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 ),28 );
$code .= substr ( md5 ( $str ),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,1 ) . (substr ( $txt,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,1 );
$i ++;
$tmp .= (substr ( $txt,1 ) ^ $md5);
}
return self::chkToken () ? $tmp : null;
}
/*
Enter description here ...
@var unkNown_type
/
private static $_key = 'lau';
}
?>

使用方法
<div class="codetitle"><a style="CURSOR: pointer" data="59886" class="copybut" id="copybut59886" onclick="doCopy('code59886')"> 代码如下:
<div class="codebody" id="code59886">
<?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,"
";
echo "DeCode:" . MD5Crypt::Decrypt ( $a,100 );
?>

加密解密

相关文章

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