php加密/解密函數

來源:互聯網
上載者:User
php加密/解密函數
加密/解密函數
用法
var_dump(Fun::Jmen('a啊',$_ENV['Only']));
var_dump(Fun::Jmun('ADYAsVzEX94%3D',$_ENV['Only']));
參數:
$str:str型,需要加密或解密的內容
$key:str型,密鈅(加密和解密的密鈅必須相同)
返回:
str型,解密或解密完的內容
  1. /**
  2. 加密/解密函數
  3. 用法
  4. var_dump(Fun::Jmen('a啊',$_ENV['Only']));
  5. var_dump(Fun::Jmun('ADYAsVzEX94%3D',$_ENV['Only']));
  6. 參數:
  7. $str:str型,需要加密或解密的內容
  8. $key:str型,密鈅(加密和解密的密鈅必須相同)
  9. 返回:
  10. str型,解密或解密完的內容
  11. /**/
  12. public static function Jmen($str,$key){
  13. $encrypt_key=md5(mt_rand(0,100));$ctr=0;$tmp='';
  14. for($i=0;$i
  15. if($ctr==strlen($encrypt_key)){$ctr=0;}$tmp.=substr($encrypt_key,$ctr,1).(substr($str,$i,1) ^ substr($encrypt_key,$ctr,1));$ctr++;
  16. }
  17. unset($encrypt_key,$ctr,$str);
  18. return rawurlencode(base64_encode(self::_m_($tmp,$key)));
  19. }
  20. public static function Jmun($str,$key){
  21. $txt=self::_m_(base64_decode(rawurldecode($str)),$key);$tmp='';
  22. for($i=0;$iunset($txt,$md5,$str,$key);
  23. return $tmp;
  24. }
  25. private static function _m_($txt,$key){
  26. $key=md5($key);$ctr=0;$tmp='';
  27. for($i=0;$ireturn $tmp;
  28. }
複製代碼
php
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.