php加密解密处理类
풀어 주다: 2016-07-25 08:42:28
-
- class SysCrypt {
-
- private $crypt_key;
-
- // 构造函数
- public function __construct($crypt_key) {
- $this -> crypt_key = $crypt_key;
- }
-
- public function php_encrypt($txt) {
- srand((double)microtime() * 1000000);
- $encrypt_key = md5(rand(0,32000));
- $ctr = 0;
- $tmp = '';
- for($i = 0;$i $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- $tmp .= $encrypt_key[$ctr].($txt[$i]^$encrypt_key[$ctr++]);
- }
- return base64_encode(self::__key($tmp,$this -> crypt_key));
- }
-
- public function php_decrypt($txt) {
- $txt = self::__key(base64_decode($txt),$this -> crypt_key);
- $tmp = '';
- for($i = 0;$i $md5 = $txt[$i];
- $tmp .= $txt[++$i] ^ $md5;
- }
- return $tmp;
- }
-
- private function __key($txt,$encrypt_key) {
- $encrypt_key = md5($encrypt_key);
- $ctr = 0;
- $tmp = '';
- for($i = 0; $i $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
- }
- return $tmp;
- }
-
- public function __destruct() {
- $this -> crypt_key = null;
- }
- }
-
-
- $sc = new SysCrypt('phpwms');
- $text = '110';
- print($sc -> php_encrypt($text));
- print('
');
- print($sc -> php_decrypt($sc -> php_encrypt($text)));
- ?>
复制代码
|
加密解密, php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
2024-10-09 22:27:01
-
2024-10-09 20:15:31
-
2024-10-09 16:42:41
-
2024-10-09 16:12:01
-
2024-10-09 13:33:51
-
2024-10-09 12:27:11
-
2024-10-09 12:00:03
-
2024-10-09 11:03:31
-
2024-09-20 15:51:33
-
2024-09-20 15:47:32