This article to: The new Too Current network blog
/** * [Encrypt data] * @e-mial [email protected] * @TIME 2017-04-07 * @WEB http://blog.iinu.com.cn * @param [data] $data [to Encrypted data] * @param [key] $key [the only way to decrypt] */functionEncrypt($data,$key){Header(' Content-type:text/html;charset=utf-8 ');$key=Md5($key);$x= 0;$len=Mb_strlen($data);$l=Mb_strlen($key); For ($i= 0;$i<$len;$i++) { If ($x==$l) {$x= 0; }$char.=$key{$x};$x++; } For ($i= 0;$i<$len;$i++) {$str.=Chr(Ord($data{$i}) + (Ord($char{$i})) % 256); } ReturnBase64_encode($str);}/** * [Decrypt encrypted data] * @e-mial [email protected] * @TIME 2017-04-07 * @WEB http://blog.iinu.com.cn * @param [data] $data [has been Encrypted data] * @param [key] $key [the only way to decrypt] */functionDecrypt($data,$key){Header(' Content-type:text/html;charset=utf-8 ');$key=Md5($key);$x= 0;$data=Base64_decode($data);$len=Mb_strlen($data);$l=Mb_strlen($key); For ($i= 0;$i<$len;$i++) { If ($x==$l) {$x= 0; }$char.=Mb_substr($key,$x, 1);$x++; } For ($i= 0;$i<$len;$i++) { If (Ord(Mb_substr($data,$i, 1)) <Ord(Mb_substr($char,$i, 1))) {$str.=Chr((Ord(Mb_substr($data,$i, 1)) + 256) -Ord(Mb_substr($char,$i, 1))); } Else {$str.= Chr (ord (mb_substr< Span class= "pun" > ( $data , $i 1 -mb_substr ( $char $i , 1)); } } return; /span>
This article to: The new Too Current network blog
PHP Data encryption and decryption