Heim  >  Artikel  >  Backend-Entwicklung  >  php加密解密处理类

php加密解密处理类

WBOY
WBOYOriginal
2016-07-25 08:42:28783Durchsuche
  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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn