PHP Cryptographic decryption class instance analysis, encryption and decryption instance Analysis _php tutorial

Source: Internet
Author: User

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 ...

  • 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.