????//????????????????demo???????????????
????$rsa = new Rsa('ssl-key');
????//??????????????
????echo 'source?????????<br />';
????$pre = $rsa->privEncrypt('???????');
????echo 'private encrypted:<br />' . $pre . '<br />';
????$pud = $rsa->pubDecrypt($pre);
????echo 'public decrypted:' . $pud . '<br />';
????//??????????????
????echo 'source:??IT??<br />';
????$pue = $rsa->pubEncrypt('??IT??');
????echo 'public encrypt:<br />' . $pue . '<br />';
????$prd = $rsa->privDecrypt($pue);
????echo 'private decrypt:' . $prd;
?????>
????????????
??????????(?????????)????????????????????????????????д???????????????????????????????????????????????????????????????????????????????????????У?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????й??????ζ???κ??????????????????????????????????????????????????????????
??????????????????: DES????3DES????TDEA????Blowfish????RC5????IDEA????
??????PHP????з?????????????
????Urlencode/Urldecode
????string urlencode ( string $str )
????/*
????1. ???????????????????????????????????URL??????
????2. urlencode??????????????urldecode??????????????????????????????????????????????????
????3. ???????????????????г??? -_. ???????з??????????????????滻??????%???????λ????????????????????????+????
????*/
???????Urlencode????????????д???&????????????:
????<?php
????$pre_url_encode="zhougang.com?username=zhougang&password=zhou"; //?????????У???????????????????URL??????????????
????$url_decode    ="zhougang.com?username=zhou&gang&password=zhou";//???????????????$_GET()???????????????;
????/*
????Array
????(
????[username] => zhou
????[gang] =>
????[password] => zhou
????)
????*/
????//??????????:
????$username="zhou&gang";
????$url_decode="zhougang.com?username=".urlencode($username)."&password=zhou";
?????>
??????????urlencode()????????
??????=> %3F
????= => %3D
????% => %25
????& => %26
???? => %5C
????base64
????string base64_decode ( string $encoded_data )
????base64_encode()??????????????????????????????????????????????????base64????????????
????base64_encode()????????????base64_decode()??????
????$data=file_get_contents($filename);
????echo base64_encode($data);
????/*??????????????????base64?????????
????????base64_decode()????????????????????????????????????????????????????????????????
????*/
???????????..???????????????????????????????????????л?
??????????????PHP?????г?????????????
????discuz??????
????<?php
????function authcode($string?? $operation = 'DECODE'?? $key = ''?? $expiry = 0) {  
????// ??????????????????????????????????????????  
????$ckey_length = 4;  
????// ???  
????$key = md5($key ? $key : $GLOBALS['discuz_auth_key']);  
????// ???a?????????  
????$keya = md5(substr($key?? 0?? 16));  
????// ???b?????????????????????  
????$keyb = md5(substr($key?? 16?? 16));  
????// ???c????仯?????????  
????$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string?? 0?? $ckey_length):
????substr(md5(microtime())?? -$ckey_length)) : '';  
????// ????????????  
????$cryptkey = $keya.md5($keya.$keyc);  
????$key_length = strlen($cryptkey);  
????// ??????10λ????????????????????????????Ч???10??26λ????????$keyb(???b)??
????//?????????????????????????????  
????// ????????????????$ckey_lengthλ?????????????$ckey_lengthλ???? ??????????????????  
????$string = $operation == 'DECODE' ? base64_decode(substr($string?? $ckey_length)) : 
????sprintf('%010d'?? $expiry ? $expiry + time() : 0).substr(md5($string.$keyb)?? 0?? 16).$string;  
????$string_length = strlen($string);  
????$result = '';  
????$box = range(0?? 255);  
????$rndkey = array();  
????// ????????  
????for($i = 0; $i <= 255; $i++) {  
????$rndkey[$i] = ord($cryptkey[$i % $key_length]);  
????}  
????// ?ù????????????????????????????????????????????????????????????  
????for($j = $i = 0; $i < 256; $i++) {  
????$j = ($j + $box[$i] + $rndkey[$i]) % 256;  
????$tmp = $box[$i];  
????$box[$i] = $box[$j];  
????$box[$j] = $tmp;  
????}  
????// ???????????  
????for($a = $j = $i = 0; $i < $string_length; $i++) {  
????$a = ($a + 1) % 256;  
????$j = ($j + $box[$a]) % 256;  
????$tmp = $box[$a];  
????$box[$a] = $box[$j];  
????$box[$j] = $tmp;  
????// ???????ó??????????????????  
????$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));  
????}  
????if($operation == 'DECODE') { 
????// ?????????Ч?????δ???????????  
????if((substr($result?? 0?? 10) == 0 || substr($result?? 0?? 10) - time() > 0) && 
????substr($result?? 10?? 16) == substr(md5(substr($result?? 26).$keyb)?? 0?? 16)) {  
????return substr($result?? 26);  
????} else {  
????return '';  
????}  
????} else {  
????// ?????????????????????????????????????????????????????????  
????// ???????????????????Щ?????????????????????????????base64????  
????return $keyc.str_replace('='?? ''?? base64_encode($result));  
????}  
????}
????????????encrypt()
????<?php
????//$string????????????????????$operation???ж?????????????E????????D????????$key?????
????function encrypt($string??$operation??$key=''){
????$key=md5($key);
????$key_length=strlen($key);
????$string=$operation=='D'?base64_decode($string):substr(md5($string.$key)??0??8).$string;
????$string_length=strlen($string);
????$rndkey=$box=array();
????$result='';
????for($i=0;$i<=255;$i++){
????$rndkey[$i]=ord($key[$i%$key_length]);
????$box[$i]=$i;
????}
????for($j=$i=0;$i<256;$i++){
????$j=($j+$box[$i]+$rndkey[$i])%256;
????$tmp=$box[$i];
????$box[$i]=$box[$j];
????$box[$j]=$tmp;
????}
????for($a=$j=$i=0;$i<$string_length;$i++){
????$a=($a+1)%256;
????$j=($j+$box[$a])%256;
????$tmp=$box[$a];
????$box[$a]=$box[$j];
????$box[$j]=$tmp;
????$result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256]));
????}
????if($operation=='D'){
????if(substr($result??0??8)==substr(md5(substr($result??8).$key)??0??8)){
????return substr($result??8);
????}else{
????return'';
????}
????}else{
????return str_replace('='??''??base64_encode($result));
????}
????}
?????>