PHP encryption and Decryption class instance analysis, encryption and decryption instance analysis
This article describes the PHP cryptographic decryption class. Share to everyone for your reference. The specific analysis is as follows:
This code supports array encryption, ciphertext expiration, various symmetric encryption
The parameters are as follows:
* @use ption::en ($string, $key);
* @param string $string strings that need to be encrypted
* @param String $skey key
* @param int $expiry ciphertext validity, encryption time valid, unit seconds, 0 for permanent effective
* @return String
1. The PHP code is as follows:
/*-Tool Library-Encrypt the password */class ption{private static $original = Array (' = ', ' + ', '/'); private static $later = Array (' o0o0o ', ' o0o 0o ', ' oo00o '); function __construct () {} private static function md5 ($skey = ') {$skey = $skey? $skey: ' UI ';//uicms::_config (' sec Urity/authkey '); return MD5 (substr ($skey, 0, 16)); }/** * @use ption::en ($string, $key); * @param string $string strings that need to be encrypted * @param string $skey key * @param int $expiry ciphertext validity, encryption time valid, unit seconds, 0 is permanent active * @return String */static Public function en ($string = ", $skey =", $expiry =0) {if (Is_array ($string)) {$string = Json_enc Ode ($string); Uicms::json ($string, true, ' en '); } $string = Str_pad ($expiry? $expiry + time:0, 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::d E ($string, $key); * @param string $string The string to decrypt * @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,) = = 0 | | substr ($result, 0, Ten)-time > 0) {return substr ($result, 10); } else {return false; } } }
2. Use the following:
"Echo" Encode: ". ($enstring = Ption::en ($STR)). '
'; Echo ' decode: '. Ption::d E ($enstring);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/987248.html www.bkjia.com true http://www.bkjia.com/PHPjc/987248.html techarticle PHP encryption and decryption class instance analysis, encryption and decryption instance analysis This article describes the PHP encryption decryption class. Share to everyone for your reference. The specific analysis is as follows: This piece of code supports array plus ...