个人意味 urlencode或base64_encode 都不算是加密,只是编码而已. 熟悉的人一看就知道采用什么编码,然后采用相应的解码函数就可以揭开,达不到加密的作用 其实 php 有个Mcrypt库,自带很多加密函数, 只要自己弄个 密钥, 就可以进行可逆加密. Here is a list of ciphers which are currently supported by the mcrypt extension. For a complete list of supported ciphers, see the defines at the end of mcrypt.h. The general rule with the mcrypt-2.2.x API is that you can access the cipher from PHP with MCRYPT_ciphername. With the libmcrypt-2.4.x and libmcrypt-2.5.x API these constants also work, but it is possible to specify the name of the cipher as a string with a call to mcrypt_module_open(). MCRYPT_3DES MCRYPT_ARCFOUR_IV (libmcrypt > 2.4.x only) MCRYPT_ARCFOUR (libmcrypt > 2.4.x only) MCRYPT_BLOWFISH MCRYPT_CAST_128 MCRYPT_CAST_256 MCRYPT_CRYPT MCRYPT_DES MCRYPT_DES_COMPAT (libmcrypt 2.2.x only) MCRYPT_ENIGMA (libmcrypt > 2.4.x only, alias for MCRYPT_CRYPT) MCRYPT_GOST MCRYPT_IDEA (non-free) MCRYPT_LOKI97 (libmcrypt > 2.4.x only) MCRYPT_MARS (libmcrypt > 2.4.x only, non-free) MCRYPT_PANAMA (libmcrypt > 2.4.x only) MCRYPT_RIJNDAEL_128 (libmcrypt > 2.4.x only) MCRYPT_RIJNDAEL_192 (libmcrypt > 2.4.x only) MCRYPT_RIJNDAEL_256 (libmcrypt > 2.4.x only) MCRYPT_RC2 MCRYPT_RC4 (libmcrypt 2.2.x only) MCRYPT_RC6 (libmcrypt > 2.4.x only) MCRYPT_RC6_128 (libmcrypt 2.2.x only) MCRYPT_RC6_192 (libmcrypt 2.2.x only) MCRYPT_RC6_256 (libmcrypt 2.2.x only) MCRYPT_SAFER64 MCRYPT_SAFER128 MCRYPT_SAFERPLUS (libmcrypt > 2.4.x only) MCRYPT_SERPENT(libmcrypt > 2.4.x only) MCRYPT_SERPENT_128 (libmcrypt 2.2.x only) MCRYPT_SERPENT_192 (libmcrypt 2.2.x only) MCRYPT_SERPENT_256 (libmcrypt 2.2.x only) MCRYPT_SKIPJACK (libmcrypt > 2.4.x only) MCRYPT_TEAN (libmcrypt 2.2.x only) MCRYPT_THREEWAY MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only) MCRYPT_TWOFISH (for older mcrypt 2.x versions, or mcrypt > 2.4.x ) MCRYPT_TWOFISH128 (TWOFISHxxx are available in newer 2.x versions, but not in the 2.4.x versions) MCRYPT_TWOFISH192 MCRYPT_TWOFISH256 MCRYPT_WAKE (libmcrypt > 2.4.x only) MCRYPT_XTEA (libmcrypt > 2.4.x only)
class coding
{
/*
加密时调用“return_coding”方法
解密时调用“converse_str”方法
注意参数
*/
//构造函数
function coding()
{
$this->coding_str = array(
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','0','1','2','3',
'4','5','6','7','8','9','8','7','6','5',
'4','3','2','1','0','1','2','3','4','5'
);
}
//生成数组,加密并返回
/*$num_l:加密位数,整型,比如“3”
$page_key:私匙密钥,字符串,比如“aabbcc”
$Skey:私匙密钥,字符串,比如“aabbcc”*/
function return_coding($num_l,$page_key,$Skey)
{
$str_len = count($this->coding_str)-1;
$Z_str = "";
for($i=0;$i<$num_l;$i++)
{
$num = rand(0,$str_len);
$Z_str .= $this->coding_str[$num];
}
$Z_str .= $page_key;
for($i=0;$i<$num_l;$i++)
{
$num = rand(0,$str_len);
$Z_str .= $this->coding_str[$num];
}
$Z_str = $this->encrypt($Z_str,$Skey); //加密运算
return $Z_str;
}
//数组逆向解出
/*$num_l:加密位数,整型,比如“3”
$page_key:页面参数
$Skey:私匙密钥,字符串,比如“aabbcc”*/
function converse_str($num_l,$page_key,$Skey)
{
$page_key_h = $this->decrypt($page_key,$Skey); //解密运算
$key_len = strlen($page_key_h) - $num_l*2;
return substr($page_key_h,$num_l,$key_len);
}
//加密算法函数
function encrypt($code,$Skey)
{
$code = base64_encode(strrev(str_rot13($code)));
$code = (string)$code;
$c_l = strlen($code);
$s_m = $Skey;
$s_l = strlen($m);
$a=0;
while ($a <$c_l)
{
$str .= sprintf ("%'02s",base_convert(ord($code{$a})+ord($s_m{$s_l % $a+1}),10,32));
$a++;
}
return $str;
}
//解密算法函数
function decrypt($code,$Skey)
{
preg_match_all("/.{2}/", $code, $arr);
$arr = $arr[0];
$s_m = $Skey;
$s_l = strlen($m);
$a = 0;
foreach ($arr as $value)
{
$str .= chr(base_convert($value,32,10)-ord($s_m{$s_l % $a+1}));
$a++;
}
$str = str_rot13(strrev(base64_decode($str)));
return $str;
}
}
Here is a list of ciphers which are currently supported by the mcrypt extension. For a complete list of supported ciphers, see the defines at the end of mcrypt.h. The general rule with the mcrypt-2.2.x API is that you can access the cipher from PHP with MCRYPT_ciphername. With the libmcrypt-2.4.x and libmcrypt-2.5.x API these constants also work, but it is possible to specify the name of the cipher as a string with a call to mcrypt_module_open(). MCRYPT_3DES
MCRYPT_ARCFOUR_IV (libmcrypt > 2.4.x only)
MCRYPT_ARCFOUR (libmcrypt > 2.4.x only)
MCRYPT_BLOWFISH
MCRYPT_CAST_128
MCRYPT_CAST_256
MCRYPT_CRYPT
MCRYPT_DES
MCRYPT_DES_COMPAT (libmcrypt 2.2.x only)
MCRYPT_ENIGMA (libmcrypt > 2.4.x only, alias for MCRYPT_CRYPT)
MCRYPT_GOST
MCRYPT_IDEA (non-free)
MCRYPT_LOKI97 (libmcrypt > 2.4.x only)
MCRYPT_MARS (libmcrypt > 2.4.x only, non-free)
MCRYPT_PANAMA (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_128 (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_192 (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_256 (libmcrypt > 2.4.x only)
MCRYPT_RC2
MCRYPT_RC4 (libmcrypt 2.2.x only)
MCRYPT_RC6 (libmcrypt > 2.4.x only)
MCRYPT_RC6_128 (libmcrypt 2.2.x only)
MCRYPT_RC6_192 (libmcrypt 2.2.x only)
MCRYPT_RC6_256 (libmcrypt 2.2.x only)
MCRYPT_SAFER64
MCRYPT_SAFER128
MCRYPT_SAFERPLUS (libmcrypt > 2.4.x only)
MCRYPT_SERPENT(libmcrypt > 2.4.x only)
MCRYPT_SERPENT_128 (libmcrypt 2.2.x only)
MCRYPT_SERPENT_192 (libmcrypt 2.2.x only)
MCRYPT_SERPENT_256 (libmcrypt 2.2.x only)
MCRYPT_SKIPJACK (libmcrypt > 2.4.x only)
MCRYPT_TEAN (libmcrypt 2.2.x only)
MCRYPT_THREEWAY
MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only)
MCRYPT_TWOFISH (for older mcrypt 2.x versions, or mcrypt > 2.4.x )
MCRYPT_TWOFISH128 (TWOFISHxxx are available in newer 2.x versions, but not in the 2.4.x versions)
MCRYPT_TWOFISH192
MCRYPT_TWOFISH256
MCRYPT_WAKE (libmcrypt > 2.4.x only)
MCRYPT_XTEA (libmcrypt > 2.4.x only)
个人觉得这样要简单一点!