当前位置: 移动技术网 > IT编程>开发语言>PHP > 支持中文的php加密解密类代码

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

2019年04月19日  | 移动技术网IT编程  | 我要评论

四川卫视真情剧场,十八禁小游戏,苦菜花 刘莹

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 );
?>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网