php支持中英文的加密解密类代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-23 14:19:56 浏览: 评论:0
本文章分享的这个php加密类是一个可以支持中文和英文的可加密码可解密的php实现类文件,有需要的同学可以参考一下,不过最好把文档编码设置为utf-8.
下面代码保存成MD5Crypt.class.php文件,代码如下:
- <?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 <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);
- } //开源代码phpfensi.com
- 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 );
- ?>
Tags: php中英文 php加密解密
- 上一篇:支持中文字母数字、自定义字体php验证码程序
- 下一篇:php高安全验证码生成程序
相关文章
- ·php加密解密实用类分享(2020-08-23)
- ·PHP加密解密类实例分析(2021-05-22)
- ·PHP实现加强版加密解密类实例(2021-06-14)
- ·PHP实现的加密解密处理类(2021-08-02)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)