Previously wrote a plus decryption of the article, also can make use of, now for security, with PHP wrote a Triple DES (3DES) positive and negative decryption function. 3DES is recognized as the safest cryptographic decryption function, but unfortunately PHP does not provide such a ready-made function, so I wrote a 3DES version of the method, 3DES has many versions, the version is the ECB mode, with PKCS7 complement, base64 do ciphertext, security level high, This function is generally used as long as you modify one of the keys.
Test:
Echo (Des3crypt ("Dragon Brother Blog", ' ENCODE '));
echo "
“;
Echo (Des3crypt ("bxc46tetfezfpts1dclzpg==", ' DECODE '));
echo "
“;
/**
* Add decryption function
* @param $str
* @param $type
* @param $key
*/
Function Des3crypt ($str, $type = ' ENCODE ', $key = ' Axnu7slkj7hkjm+x4bfbjsjqkde ') {
if (empty ($STR) && $str! = 0) {
return false;
}
$td = Mcrypt_module_open (Mcrypt_3des, ", MCRYPT_MODE_ECB,");
$key = Base64_decode ($key);
Mcrypt_generic_init ($TD, $key, ' 12345678′ ');
if (strtoupper ($type) = = ' ENCODE ') {
$str = padding ($str);
$data = Mcrypt_generic ($TD, $STR);
}elseif (strtoupper ($type) = = ' DECODE ') {
$str = Base64_decode ($STR);
$data = Mdecrypt_generic ($TD, $STR);
}
//Encryption
Mcrypt_generic_deinit ($TD);
End
Mcrypt_module_close ($TD);
if (Strtoupper ($type) = = ' ENCODE ') {
$data = Removebr (Base64_encode ($data));
} ElseIf (Strtoupper ($type) = = ' DECODE ') {
$data = removepadding ($data);
}
return $data;
}
Delete a fill character
function removepadding ($STR) {
$len = strlen ($STR);
$newstr = "";
$str = Str_split ($STR);
for ($i = 0; $i < $len; $i + +) {
if (!in_array ($str [$i],array (Chr (0), Chr (1), Chr (2), Chr (3), Chr (4), Chr (5), Chr (6), Chr (7), Chr (8))) {
$newstr. = $str [$i];
}
}
return $newstr;
}
Fill password, fill to multiples of 8, PKCS7 | Pkcs5
function padding ($str, $PKCS = 5) {
if ($PKCS = = 5) {
$pad = 8– (strlen ($STR)% 8);
$str. = Str_repeat (Chr ($pad), $pad);
}elseif ($pkcs = = 7) {
$len = 8–strlen ($str)% 8;
for ($i = 0; $i < $len; $i + +) {
$str. = chr (0);
}
}
return $str;
}
/**
* Http://52blogger.com Long Brother Blog All rights reserved, welcome reprint, reprint please must indicate source, violate edition must investigate.
*/
Remove carriage returns and line feeds
function Removebr ($STR) {
$len = strlen ($STR);
$newstr = "";
$str = Str_split ($STR);
for ($i = 0; $i < $len; $i + +) {
if ($str [$i]! = ' \ n ' and $str [$i]! = ' \ r ') {
$newstr. = $str [$i];
}
}
return $newstr;
}
Article Source: Dragon Brother Blog Original: http://www.52blogger.com/archives/821
http://www.bkjia.com/PHPjc/363852.html www.bkjia.com true http://www.bkjia.com/PHPjc/363852.html techarticle previously wrote a plus decryption of the article, also can make use of, now for security, with PHP wrote a Triple DES (3DES) of the positive and negative decryption function. 3DES is recognized as the safest encryption decryption ...