php加密解密处理类

WBOY
풀어 주다: 2016-07-25 08:42:28
원래의
785명이 탐색했습니다.
  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 학습자의 빠른 성장을 도와주세요!