Encrypt and decrypt PHP cryptographic decryption class

Source: Internet
Author: User
Tags ord uppercase letter
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 0, O, O, L and other easily confusing characters
$chars = ' abcdefghjklmnpqrstuvwxyz23456789abcdefghijkmnpqrstuvwxyz ';
Break
Case 2://Pure Digital
$chars = ' 0123456789 ';
Break
Case 3://full digit + uppercase letter
$chars = ' abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz ';
Break
Case 4://full digit + uppercase letter + 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 Clear text or ciphertext
* $operation encrypt encode or decrypt decode
* $key Key
* $expiry Key Expiration date
*/
function Authcode ($string, $operation = ' DECODE ', $key = ", $expiry = 0) {
$ckey _length = 4;
$key = MD5 ($key);
$keya = MD5 (substr ($key, 0, 16));
$KEYB = MD5 (substr ($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 < $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, ten) = = 0 | | substr ($result, 0,)-time () > 0) && substr ($result, ten, +) = = SUBSTR (MD 5 (substr ($result, +). $keyb), 0, 16)) {
Return substr ($result, 26);
} else {
Return ';
}
} else {
Return $KEYC. Str_replace (' = ', ' ', Base64_encode ($result));
}
}

The above describes the encryption and decryption of PHP encryption and decryption classes, including the content of encryption and decryption, I hope that the PHP tutorial interested in a friend helpful.

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