about using PHP to generate encrypted zip file solutions

Source: Internet
Author: User
about using PHP to generate encrypted Zip files
phpMyAdmin There is a zip.lib.php, you can generate a zip file, but not encrypted. That big Brother knows how to encrypt? (I said encryption refers to when extracting the file back to the request for the decompression password).
Online to find a lot of, basically borrowing winrar or zip through the command line encryption, there is no PHP generated encrypted zip file?

Now how can not choose experts, but also want to ask the elder brother to see it ...

------Solution--------------------
Help the top!!!!!
------Solution--------------------
1 Existing Operations Zip PHP provides functions divided into two major categories, one is ziparchive zip, there is no ability to find the file plus password.
2 The simplest way is to use WinRAR or zip encryption via command line, this you do not choose.
3 also is the analysis of encrypted and unencrypted files, through the file read and write operation, this is not very feasible, and the implementation of the technical requirements are high.

------Solution--------------------
Does not seem to be encrypted, encryption uses other techniques
------Solution--------------------
Encryption rules itself, the simplest character conversion, such as a "AAAAA", after encryption you want to change it "bbbbb".


/**
* Passport Encryption function
*
* @param string waits for the encrypted original string
* @param string private key (for decryption and encryption)
*
* @return The result of a string literal being encrypted with a private key
*/
function Passport_encrypt ($txt, $key)
{

Use the random number generator to generate 0~32000 values and MD5 ()
Srand (Double) microtime () * 1000000);
$encrypt _key = MD5 (rand (0, 32000));

Variable initialization
$ctr = 0;
$tmp = ";

For loop, $i starting from 0 to an integer less than $txt string length
for ($i = 0; $i < strlen ($txt); $i + +)
{
$ctr zeroed If $ctr = $encrypt the length of the _key
$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
The $tmp string adds two bits at the end, the first of which is the $ctr bit of the $encrypt _key,
The second content is the $i of the $txt and the $ctr bit of the $encrypt _key. Then $ctr = $ctr + 1
$tmp. = $encrypt _key[$ctr]. ($txt [$i] ^ $encrypt _key[$ctr + +]);
}

Returns the result with the result of the BASE65 encoded result of the Passport_key () function return value
Return Base64_encode (Passport_key ($tmp, $key));
}

/**
* Passport decryption function
*
* @param string of strings after encryption
* @param string private key (for decryption and encryption)
*
* Results of @return string strings being decrypted by private key
*/
function Passport_decrypt ($txt, $key)
{
The result of the $txt is that the encrypted string is Base64 decoded and then, together with the private key,
return value after processing by the Passport_key () function
$txt = Passport_key (Base64_decode ($txt), $key);

Variable initialization
$tmp = ";
For loop, $i starting from 0 to an integer less than $txt string length
for ($i = 0; $i < strlen ($txt); $i + +)
{
$tmp string adds a bit to the end of the $txt $i bit,
With $txt $i + 1-bit XOR. Then $i = $i + 1
$tmp. = $txt [$i] ^ $txt [+ + $i];
}

Returns the value of the $tmp as a result
return $tmp;
}

/**
* Passport Key processing function
*
* @param string to be encrypted or to be decrypted
* @param string private key (for decryption and encryption)
*
* @return The key after string processing
*/
function Passport_key ($txt, $encrypt _key)
{
Assigns $encrypt _key to $encrypt _key by MD5 ()
$encrypt _key = MD5 ($encrypt _key);

Variable initialization
$ctr = 0;
$tmp = ";

For loop, $i starting from 0 to an integer less than $txt string length
for ($i = 0; $i < strlen ($txt); $i + +)
{
$ctr zeroed If $ctr = $encrypt the length of the _key
$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
$tmp string adds a bit to the end of the $txt $i bit,
With $encrypt _key $ctr + 1-bit XOR. Then $ctr = $ctr + 1
$tmp. = $txt [$i] ^ $encrypt _key[$ctr + +];
}

Returns the value of the $tmp as a result
return $tmp;
}

/**
* Passport Information (array) encoding function
*
* @param array to encode
*
* @return string array of encoded strings
  • 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.