设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 177|回复: 0

一个简单的php加密解密函数(动态加密)

[复制链接]
发表于 2014-1-8 10:39:04 | 显示全部楼层 |阅读模式
Code:
  1. function encode_pass($tex,$key,$type="encode"){
  2. $chrArr=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',
  3. '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',
  4. '0','1','2','3','4','5','6','7','8','9');
  5. if($type=="decode"){
  6. if(strlen($tex)<14)return false;
  7. $verity_str=substr($tex, 0,8);
  8. $tex=substr($tex, 8);
  9. if($verity_str!=substr(md5($tex),0,8)){
  10. //完整性验证失败
  11. return false;
  12. }
  13. }
  14. $key_b=$type=="decode"?substr($tex,0,6):$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62];
  15. $rand_key=$key_b.$key;
  16. $rand_key=md5($rand_key);
  17. $tex=$type=="decode"?base64_decode(substr($tex, 6)):$tex;
  18. $texlen=strlen($tex);
  19. $reslutstr="";
  20. for($i=0;$i<$texlen;$i++){
  21. $reslutstr.=$tex{$i}^$rand_key{$i%32};
  22. }
  23. if($type!="decode"){
  24. $reslutstr=trim($key_b.base64_encode($reslutstr),"==");
  25. $reslutstr=substr(md5($reslutstr), 0,8).$reslutstr;
  26. }
  27. return $reslutstr;
  28. }
  29. $psa=encode_pass("phpcode","taintainxousad");
  30. echo $psa;
  31. echo encode_pass($psa,"taintainxousad",'decode');
复制代码

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2026-2-5 14:58 , Processed in 0.011594 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表