首页 > 资讯列表 > 编程/数据库 >> PHP

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

PHP 2014-12-07 05:42:02 转载来源: 网络整理/侵权必删

本文是一个支持中文的php加密解密类代码示例,感兴趣的同学参考下。 php代码类: <?php ! 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

本文是一个支持中文php加密解密代码示例,感兴趣的同学参考下。
php代码类:


<?php
! 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

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

 


标签: 支持 中文 php 加密解密 代码


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持