PHP加密函數 Javascript/Js 解密函數_php技巧

來源:互聯網
上載者:User

以下函數代碼中“123456” 是個加密的key,自己可以隨便改。
php加密,js解密,貌似沒什麼意義,主要是key在js中會被看到。
不過在某些地方可能會用到。

PHP加密函數

複製代碼 代碼如下:

<?php  
 function strencode($string) {  
    $string = base64_encode ( $string );  
    $key = md5 ( '123456' );  
    $len = strlen ( $key ); 
    $code = '';  
    for($i = 0; $i < strlen ( $string ); $i ++) {      
 $k = $i % $len;      
 $code .= $string [$i] ^ $key [$k];  
    }  
    return base64_encode ( $code );  
}  
echo strencode ( 'abced你好我是你們定的點點滴滴asd@#$)()*&*&*' );  
?> 

js解密函數:

複製代碼 代碼如下:

<script>  
function strencode(string) {  
key = calcMD5('123456');  
string = Base64.decode(string);  
 len = key.length;  
 code = '';  
 for (i = 0; i < string.length; i++) {  
     k = i % len;  
     code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k));  
 }  
 return Base64.decode(code);  
}
alert(strencode('PGZ6Cz40Z1JCWCYNRVtSDwsvfVsIexpcEFN0DU0OSQkXQUIPCQxnV1NLDA9SSw8PF1JhWxAHZ18FAGIncUFiFS5yWxAuClxUf15fXA=='));  
</script> 

PHP 加密 & JS 解密2

複製代碼 代碼如下:

<?php
if(!function_exists(jm))
{
    function jm($str){
  $len = strlen($str);
  for($i=0;$i<$len;$i++)
  {
   $ascc=ord($str[$i]);
   if($ascc<128)
   {
    $ascc=$ascc^7;
   }
   $res.=chr($ascc);
  }
  return $res;
    }//end function
}
echo "<script>
xflag=true;
function xcount(xh){
 if(!xflag) return;
 var xc=\"\",xd=new Array(),xe=\"\",xf=0;
 for(i=0;i<xh.length;i++){
  xa=xh.charCodeAt(i);
  if(xa<128)xa=xa^7;
  xe+=String.fromCharCode(xa);
  if(xe.length>80){
   xd[xf++]=xe;xe=\"\";
   }
 }
 xc=xd.join(\"\")+xe;
 document.write(xc);
}</script>";
$check_count = addslashes(jm("<script>alert('測試咯~~~');</script>"));
$check_count="<SCRIPT LANGUAGE=\"JavaScript\">xcount(\"$check_count\");</SCRIPT>";
echo "$check_count";
echo "<!-- count ended -->";

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.