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);