VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • 一组PHP加密解密函数分享

这篇文章主要介绍了一组PHP加密解密函数分享,需要的朋友可以参考下。

  1. <?php 
  2. /** 
  3. *功能:对字符串进行加密处理 
  4. *参数一:需要加密的内容 
  5. *参数二:密钥 
  6. */ 
  7. function passport_encrypt($str,$key){ //加密函数 
  8. srand((double)microtime() * 1000000); 
  9. $encrypt_key=md5(rand(0, 32000)); 
  10. $ctr=0; 
  11. $tmp=''; 
  12. for($i=0;$i<strlen($str);$i++){ 
  13. $ctr=$ctr==strlen($encrypt_key)?0:$ctr; 
  14. $tmp.=$encrypt_key[$ctr].($str[$i] ^ $encrypt_key[$ctr++]); 
  15. } 
  16. return base64_encode(passport_key($tmp,$key)); 
  17. } 
  18. /** 
  19. *功能:对字符串进行解密处理 
  20. *参数一:需要解密的密文 
  21. *参数二:密钥 
  22. */ 
  23. function passport_decrypt($str,$key){ //解密函数 
  24. $str=passport_key(base64_decode($str),$key); 
  25. $tmp=''; 
  26. for($i=0;$i<strlen($str);$i++){ 
  27. $md5=$str[$i]; 
  28. $tmp.=$str[++$i] ^ $md5; 
  29. } 
  30. return $tmp; 
  31. } 
  32.  
  33. /** 
  34. *辅助函数 
  35. */ 
  36. function passport_key($str,$encrypt_key){ 
  37. $encrypt_key=md5($encrypt_key); 
  38. $ctr=0; 
  39. $tmp=''; 
  40. for($i=0;$i<strlen($str);$i++){ 
  41. $ctr=$ctr==strlen($encrypt_key)?0:$ctr; 
  42. $tmp.=$str[$i] ^ $encrypt_key[$ctr++]; 
  43. } 
  44. return $tmp; 
  45. } 
  46. $str='作者:WWW.JB51.NET; 
  47. $key='jb51net'; 
  48. $encrypt=passport_encrypt($str,$key); 
  49. $decrypt=passport_decrypt($encrypt,$key); 
  50.  
  51. echo '原文:',$str."<br><hr>"; 
  52. echo '密文:',$encrypt."<br><hr>"; 
  53. echo '译文:',$decrypt."<br><hr>"; 
  54. ?> 
  55.  

出处:http://www.phpfensi.com/php/20210207/13619.html


相关教程