php加密解密处理类

WBOY
发布: 2016-07-25 08:42:28
原创
783 人浏览过
  1. class SysCrypt {
  2. private $crypt_key;
  3. // 构造函数
  4. public function __construct($crypt_key) {
  5. $this -> crypt_key = $crypt_key;
  6. }
  7. public function php_encrypt($txt) {
  8. srand((double)microtime() * 1000000);
  9. $encrypt_key = md5(rand(0,32000));
  10. $ctr = 0;
  11. $tmp = '';
  12. for($i = 0;$i $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  13. $tmp .= $encrypt_key[$ctr].($txt[$i]^$encrypt_key[$ctr++]);
  14. }
  15. return base64_encode(self::__key($tmp,$this -> crypt_key));
  16. }
  17. public function php_decrypt($txt) {
  18. $txt = self::__key(base64_decode($txt),$this -> crypt_key);
  19. $tmp = '';
  20. for($i = 0;$i $md5 = $txt[$i];
  21. $tmp .= $txt[++$i] ^ $md5;
  22. }
  23. return $tmp;
  24. }
  25. private function __key($txt,$encrypt_key) {
  26. $encrypt_key = md5($encrypt_key);
  27. $ctr = 0;
  28. $tmp = '';
  29. for($i = 0; $i $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  30. $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
  31. }
  32. return $tmp;
  33. }
  34. public function __destruct() {
  35. $this -> crypt_key = null;
  36. }
  37. }
  38. $sc = new SysCrypt('phpwms');
  39. $text = '110';
  40. print($sc -> php_encrypt($text));
  41. print('
    ');
  42. print($sc -> php_decrypt($sc -> php_encrypt($text)));
  43. ?>
复制代码

加密解密, php


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!