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. returnbase64_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. ($i = 0;$i $md5 = $txt[$i];
  21. $tmp .= $txt[++$i] ^ $md5;
  22. }
  23. return $tmp;
  24. }
  25. プライベート関数 __key($txt,$encrypt_key) {
  26. $encrypt_key = md5($encrypt_key);
  27. $ctr = 0;
  28. $tmp = '';
  29. for($i = 0 ; $i $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('< ;br>');
  42. print($sc -> php_decrypt($sc -> php_encrypt($text)));
  43. ?>
复制代

加密解密、php


関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!