教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php自定义加密函数、解密的例子

php自定义加密函数、解密的例子

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供php自定义加密函数、解密的例子等资源,欢迎您收藏本站,我们将为您提供最新的php自定义加密函数、解密的例子资源
本文章这里给各位整理了几个非常不错的加密,解密例子,希望这些例子来给你工作带来帮助。

加密就是将一些字符转换为另一个字符串的过程,简单的说就是把大门上锁,并且只有你有开启的钥匙。作为一个程序员都应该有属于自己的加密方式,目前最流行的加密算法就是MD5()加密方式。但是在网站已经有了破解的软件用起来也不是很安全。下面简单的介绍一下自定义的加密函数。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6420')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6420>

“/*加密*/

function addcoder($str)

    {

        $yuan = 'abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w Jxy8z9K0';

        $jia = 'zAy x 1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a';

       if ( strlen($str) == 0) return false;

for($i = 0;$i<strlen($str);$i )

        {

            for($j = 0;$j<strlen($yuan);$j )                         

{

if($str[$i]==$yuan[$j])

                    {

$results.= $jia[$j];

break;

}

            }

        }

       return $results;

    }

 


/*解密*/

function removecoder($str)

{

        $yuan = 'abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w Jxy8z9K0';

        $jia = 'zAy x 1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a';

       If (strlen($str)==0) return false;

  for($i = 0;$i< strlen($str);$i )

{

 for($j = 0;$j<strlen($jia);$j )

  {

  if($str[$i]==$jia[$j]) 

{

$results .= $yuan[$j];

break;

}

  }

}

       return $results;

    }

$str = "www.jiaochengji.com";
echo "加密前:".$str."<br >";
$str1= addcoder($str);
echo "加密后:".$str1."<br >";
$str2= removecoder($str1);
echo "解密后:".$str2."<br >";

例子二,利用md5 base64_encode进行编辑处理。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7917')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7917>

<?php
//www.jiaochengji.com
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = '';
for($i = 0;$i < strlen($txt); $i ) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr ]);
}
return base64_encode(passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
$txt = passport_key(base64_decode($txt), $key);
$tmp = '';
for($i = 0;$i < strlen($txt); $i ) {
$md5 = $txt[$i];
$tmp .= $txt[ $i] ^ $md5;
}
return $tmp;
}
function passport_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;
}
?>

您可能感兴趣的文章:
php base64加密解密的实现代码
PHP加密扩展库Mcrypt的例子
有关discuz程序中PHP加密函数的原理分析
php加密函数md5,crypt,base64_encode的用法介绍
php 加密、解密类与调用实例
php crypt函数加密和解密的实例分享
PHP开发者如何做好密码保护以及Laravel底层密码存储和验证实现
php mcrypt启用、加密以及解密的方法介绍
PHP 数据加密的方法
php生成随机产生六位数密码的代码

[关闭]
~ ~