This article mainly introduces the PHP encryption and decryption of the relevant implementation skills, interested in the reference of friends, hope to help you.
Specific as follows:
<?phpclass ender{private $enkey;//encryption decryption with the key private $rep _char= ' # '; Replace the = in the encrypted base64 string, because = is forbidden in some cases,//this can be replaced with an allowable character. The construction parameter is the key public function __construct ($key = ") {if (! $key) {$this->enkey= $key; }}//Set key http://blog.ddian.cn public function Set_key ($key) {$this->enkey= $key; } Private Function KeyED ($txt, $encrypt _key) {$encrypt _key = MD5 ($encrypt _key); $ctr = 0; $tmp = ""; for ($i =0; $i <strlen ($txt); $i + +) {if ($ctr ==strlen ($encrypt _key)) $ctr = 0; $tmp. = substr ($txt, $i, 1) ^ substr ($encrypt _key, $ctr, 1); $ctr + +; } return $tmp; }//Encrypt string public function encrypt ($txt, $key = ") {if (! $key) {$key = $this->enkey; } srand (Double) microtime () *1000000); $encrypt _key = MD5 (rand (0,32000)); $ctr = 0; $tmp = ""; for ($i =0; $i <strlen ($txt); $i + +) {if ($ctr ==strlen ($encrypt _key)) $ctr = 0; $tmp. = substr ($encrypt _key, $ctr, 1). (Substr ($txt, $i, 1) ^ substr ($encrypt _key, $ctr, 1)); $ctr + +; } $r =base64_encode ($this-≫keyed ($tmp, $key)); $r =str_replace (' = ', $this->rep_char, $r); return $r; }//Decrypt the string public function decrypt ($txt, $key = ') {$txt =str_replace ($this->rep_char, ' = ', $txt); $txt =base64_decode ($txt); if (! $key) {$key = $this->enkey; } $txt = $this->keyed ($txt, $key); $tmp = ""; for ($i =0; $i <strlen ($txt); $i + +) {$MD 5 = substr ($txt, $i, 1); $i + +; $tmp. = (substr ($txt, $i, 1) ^ $md 5); } return $tmp; }}
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP using the Magickwand module to manipulate the image to add a watermark method
The function of using curl to forge IP in PHP
PHP for the current encoding of the judgment and corresponding code conversion implementation techniques