cls certificate.php,php加密解密处理类
PHP加密解密也是常有的事,發(fā)現(xiàn)discuz論壇里的PHP加密解密處理類代碼,感覺(jué)挺不錯(cuò),在用的時(shí)候,要參考Discuz論壇的passport相關(guān)函數(shù),后面我會(huì)附上使用方法。
php加密解密處理類<?php
/*========================================================
= 文件名稱:cls.sys_crypt.php
= 摘 要:php加密解密處理類 www.qdxw.net
= 參 考:Discuz論壇的passport相關(guān)函數(shù)
=========================================================*/
class SysCrypt {
private $crypt_key;
// 構(gòu)造函數(shù)
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
$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;
}
}
?>
使用方法說(shuō)明<?php
//使用前請(qǐng)先引入類文件,如:
include 'cls.sys_crypt.php';
$sc = new SysCrypt('phpwms');
$text = '110';
print($sc -> php_encrypt($text));
print('
');
print($sc -> php_decrypt($sc -> php_encrypt($text)));
?>
總結(jié)
以上是生活随笔為你收集整理的cls certificate.php,php加密解密处理类的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php读取配置文件连接mysql数据库,
- 下一篇: idea调试怎么跳出循环_IDEA调试技