<?php
/**
* PHP加密类
* 琼台博客
*/
class Jiami{
// 公钥
protected $key = 'lee';
private 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;
}
public function encrypt($txt,$key=''){
if(empty($key)){
$key=$this->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++;
}
return $this->keyED($tmp,$key);
}
public function decrypt($txt,$key=''){
if(empty($key)){
$key=$this->key;
}
$txt = $this->keyED($txt,$key);
$tmp = '';
for ($i=0;$i<strlen($txt);$i++){
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
public function setKey($key){
if(empty($key)){
return null;
}
$this->key=$key;
}
public function getPK(){
return $this->key;
}
}
<?php
// 先包含加密类
require_once('jiami.class.php');
// 要加密的字符串
$string = 'http://www.1sucai.cn';
// 实例化加密类
$jiami= new Jiami();
// 设置公钥
$jiami->setKey('qttc');
// 加密字符串
$enc = $jiami->encrypt($string,$jiami->getPK());
// 解密字符串
$dec = $jiami->decrypt($enc,$jiami->getPK());
echo '<meta charset="utf-8" />';
echo '加密前 : '.$string .'<br/>';
echo '加密后 : '.$enc .'<br/>';
echo '解密后 : '.$dec;
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有