最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php支持中英文的加密解密类代码
时间:2022-06-24 15:59:43 编辑:袖梨 来源:一聚教程网
下面代码保存成MD5Crypt.class.php文件
代码如下 | 复制代码 |
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 */ 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 */ 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'; } ?> |
用法
代码如下 | 复制代码 |
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 ); ?> |
相关文章
- 炉石传说血DK卡组怎么样 炉石传说血DK卡组推荐介绍 11-05
- 咒术回战幻影夜行官网在哪里 咒术回战幻影夜行官网地址介绍 11-05
- 蚂蚁庄园今天答题答案2024年10月26日 11-05
- 以闪亮之名变装物语甜趣篇怎么玩 11-05
- 闪耀暖暖永夜禁锢怎么玩 11-05
- 闪耀暖暖永夜禁锢怎么玩 闪耀暖暖永夜禁锢活动介绍 11-05