The main content of this article is about the PHP encryption class, has a certain reference value, now share to everyone, the need for friends can refer to
<?phpnamespace app\index\controller;class crypt{Private $key = ""; Public function __construct ($key = null) {if (!is_null ($key)) {$this->key = $key; }}//Cryptographic function Public Function Passport_encrypt ($txt) {srand (double) microtime () * 10 00000); $encrypt _key = MD5 (rand (0, 32000)); $ctr = 0; $tmp = "; for ($i = 0; $i < strlen ($txt); $i + +) {$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr; $tmp. = $encrypt _key[$ctr]. ($txt [$i] ^ $encrypt _key[$ctr + +]); } return UrlEncode (Base64_encode ($this->passport_key ($tmp, $this->key)); }//Decryption function Public function Passport_decrypt ($txt) {$txt = $this->PASSP Ort_kEY (Base64_decode (UrlDecode ($txt)), $this->key); $tmp = "; for ($i = 0; $i < strlen ($txt); $i + +) {$MD 5 = $txt [$i]; $tmp. = $txt [+ + $i] ^ $MD 5; } return $tmp; } Private Function Passport_key ($txt, $encrypt _key) {$encrypt _key = MD5 ($encrypt _key); $ctr = 0; $tmp = "; for ($i = 0; $i < strlen ($txt); $i + +) {$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr; $tmp. = $txt [$i] ^ $encrypt _key[$ctr + +]; } return $tmp; } }