PHP Data encryption and decryption

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.