zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

2023-06-13 09:14:31 时间
php代码类:
复制代码代码如下:

<?php
/**
*Copyright(c)2011-01XatuDream
*XatuDreamAllRightsReserved.
*Support:185390516.qzone.qq.com
*QQ:185390516
*Author:LauVersion:1.01
*Date:2010-08-1209:28:32
*/
!defined("WORKSPACE")&&exit("AccessDenied!");
classMD5Crypt{
/**
*Enterdescriptionhere...
*@paramunknown_type$str
*@returnstring
*/
publicfinalstaticfunctionmdsha($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);
returnself::chkToken()?$code:null;
}
/**
*Enterdescriptionhere...
*@paramunknown_type$param
*/
privatefinalstaticfunctionchkToken(){
returntrue;
}
/**
*Enterdescriptionhere...
*@paramunknown_type$txt
*@paramunknown_type$encrypt_key
*@returnAmbigous<string,boolean>
*/
privatefinalstaticfunctionkeyED($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;
}
/**
*Enterdescriptionhere...
*@paramunknown_type$txt
*@paramunknown_type$key
*@returnstring
*/
publicfinalstaticfunctionEncrypt($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);
returnself::chkToken()?$_code:null;
}
/**
*Enterdescriptionhere...
*@paramunknown_type$txt
*@paramunknown_type$key
*@returnAmbigous<string,boolean>
*/
publicfinalstaticfunctionDecrypt($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);
}
returnself::chkToken()?$tmp:null;
}
/**
*Enterdescriptionhere...
*@varunknown_type
*/
privatestatic$_key="lau";
}
?>

使用方法:
复制代码代码如下:

<?php//CodeStart
/**
*Copyright(c)2011XatuDream
*XatuDreamAllRightsReserved.
*Support:185390516.qzone.qq.com
*QQ:185390516
*Author:LoveCrystalVersion:1.01
*Date:2011-9-204: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);
?>