I also share a PHP encryption and decryption class.

Source: Internet
Author: User
Supports array encryption, ciphertext validity period, and various symmetric encryption * @ useption: en ($ string, $ key ); * @ paramString $ string the string to be encrypted * @ paramString $ skey key * @ paramint $ expiry ciphertext validity period, effective during encryption, in seconds, 0 is permanently valid * @ returnString none **-tool library-encrypted password unlock *

Supports array encryption, ciphertext validity period, and various symmetric encryption * @ useption: en ($ string, $ key ); * @ paramString $ string the string to be encrypted * @ paramString $ skey key * @ paramint $ expiry ciphertext validity period, effective during encryption, in seconds, 0 is permanently valid * @ returnString NONE/**-tool library-password encryption * ========

Supports array encryption, ciphertext validity period, and various symmetric encryption

* @ Use ption: en ($ string, $ key );
* @ Param String $ string the String to be encrypted
* @ Param String $ skey key
* @ Param int $ expiry ciphertext validity period. Valid during encryption. Unit: seconds. 0 indicates permanent validity.
* @ Return String <无>
/**-Tool library-password encryption and decryption * ================================== ========================================================== ======= * All Rights Reserved: youai network and reserves all rights. * Website address: http://www.uicms.cn * Mailbox admin@uicms.net * -------------------------------------------------------------------------------- * this is not a free software! You can only modify and use the program code without commercial purpose. You cannot re-release the program code for any form or purpose. For secondary development or commercial use, it must be approved by the author. * ===================================================== ============================================================= */Class ption {private static $ original = array ('= ', '+', '/'); private static $ later = array ('0o0o', '0o0o', 'oo00o'); function _ construct () {} private static function md5 ($ skey = '') {$ skey = $ skey? $ Skey: 'ui'; // uicms: _ config ('security/authkey'); return md5 (substr ($ skey, 0, 16 ));} /*** @ use ption: en ($ string, $ key ); * @ param String $ string the String to be encrypted * @ param String $ skey key * @ param int $ expiry ciphertext validity period, valid during encryption, in seconds, 0 is permanently valid * @ return String */static public function en ($ string = '', $ skey ='', $ expiry = 0) {if (is_array ($ string) {$ string = json_encode ($ string); // uicms: json ($ string, true, 'en ');} $ String = str_pad ($ expiry? $ Expiry + TIME: 0, 10, 0 ). $ string; $ strArr = str_split (base64_encode ($ string); $ strCount = count ($ strArr); $ skey = static: md5 ($ skey ); foreach (str_split ($ skey) as $ key = >$ value) {$ key <$ strCount & $ strArr [$ key]. = $ value;} return str_replace (self ::$ original, self ::$ later, join ('', $ strArr);}/*** @ use ption :: de ($ string, $ key ); * @ param String $ string the String to be decrypted * @ param String $ skey key * @ return string */static public function de ($ String = '', $ skey = '') {$ strArr = str_split (str_replace (self ::$ later, self ::$ original, $ string), 2); $ strCount = count ($ strArr ); $ skey = static: md5 ($ skey); foreach (str_split ($ skey) as $ key => $ value) {$ key <= $ strCount & $ strArr [$ key] [1] ===$ value & $ strArr [$ key] = $ strArr [$ key] [0 ];} $ result = base64_decode (join ('', $ strArr); if (substr ($ result, 0, 10) = 0 | substr ($ result, 0, 10) -TIME> 0) {return substr ($ result, 10) ;}else {return false ;}}}
$str['username'] = 'oschina';$str['pw'] = '123456';$str['huoxin'] = '!@#$%^&';echo "string : " . $str . " 
";echo "encode : " . ($enstring = ption::en($str)) . '
';echo "decode : " . ption::de($enstring);

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.