PHP encryption decryption class instance code _php instance

Source: Internet
Author: User

The

key code looks like this:

<?php function I_array_column ($input, $columnKey, $indexKey =null) {if (!function_exists (' Array_column ')) {$
Columnkeyisnumber = (Is_numeric ($columnKey)) True:false;
$indexKeyIsNull = (Is_null ($indexKey)) True:false;
$indexKeyIsNumber = (Is_numeric ($indexKey)) True:false;
$result = Array (); foreach (array) $input as $key => $row) {if ($columnKeyIsNumber) {$tmp = Array_slice ($row, $columnKey, 1); $tmp = (is_
Array ($tmp) &&!empty ($tmp))? Current ($TMP): null; }else{$tmp = isset ($row [$columnKey])? $row [$columnKey]:null;} if (! $indexKeyIsNull) {if ($indexKeyIsNumber) {$key =
Array_slice ($row, $indexKey, 1);
$key = (Is_array ($key) &&!empty ($key))? Current ($key): null;
$key = is_null ($key) 0: $key;
}else{$key = isset ($row [$indexKey])? $row [$indexKey]:0;}}
$result [$key] = $tmp;
return $result;
}else{return Array_column ($input, $columnKey, $indexKey);} function Randcode ($len, $mode = 2) {$rcode = '; switch ($mode) {Case 1://Remove easily confusing characters such as 0, O, O, l, etc. $chars = ' abcdefghjklmnpqrstuvwx YZ23456789abcdefghijkmnpqrstuvwxyz ';
Break
Case 2://Pure digital $chars = ' 0123456789 ';
Break
Case 3://Full number + uppercase and lowercase letters $chars = ' abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz ';
Break Case 4://Full number + uppercase and lowercase + some special characters $chars = ' abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz~!@#$%^&* () '
;
Break
$count = strlen ($chars)-1;
Mt_srand (Double) microtime () * 1000000);
for ($i = 0; $i < $len; $i + +) {$rcode. = $chars [Mt_rand (0, $count)];} return $rcode; }/** * $string plaintext or ciphertext * $operation encrypt encode or decrypt the decode * $key key * $expiry key validity */function Authcode ($string, $operation = ' DECODE ', $key = ', $expiry = 0) {$ckey _length = 4; $key = MD5 ($key); $keya = MD5 (substr ($key, 0,); $keyb = MD5 (Subs
TR ($key, 16, 16)); $KEYC = $ckey _length?
($operation = = ' DECODE ' substr ($string, 0, $ckey _length): substr (MD5 (Microtime ()),-$ckey _length)): ";
$cryptkey = $keya. MD5 ($keya. $KEYC);
$key _length = strlen ($cryptkey); $string = $operation = = ' DECODE '? Base64_decode (substr ($string, $ckEy_length): sprintf ('%010d ', $expiry? $expiry + Time (): 0). substr (MD5 ($string. $keyb), 0). $string;
$string _length = strlen ($string);
$result = ';
$box = Range (0, 255);
$rndkey = Array ();
for ($i = 0; $i <= 255 $i + +) {$rndkey [$i] = Ord ($cryptkey [$i% $key _length]);} for ($j = $i = 0; $i < 256; $i + +) {
$j = ($j + $box [$i] + $rndkey [$i])% 256;
$tmp = $box [$i];
$box [$i] = $box [$j];
$box [$j] = $tmp;
for ($a = $j = $i = 0; $i < $string _length $i + +) {$a = ($a + 1)% 256; $j = ($j + $box [$a])% 256; $tmp = $box [$a];
$box [$a] = $box [$j];
$box [$j] = $tmp;
$result. = Chr (ord ($string [$i]) ^ ($box [($box [$a] + $box [$j])% 256]); } if ($operation = = ' DECODE ') {if (substr ($result, 0,) = 0 | | substr ($result, 0)-time () > 0) && subst  R ($result) = = substr (MD5 (substr ($result,). $keyb), 0) {return substr ($result);} else {return ';}} else {return $KEYC. Str_replace (' = ', ', Base64_encode ($result));}

The above is a small set to introduce the PHP encryption and decryption class example code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.