-
-
/** - * Passport encryption function
- *
- * @param string The original string waiting to be encrypted
- * @param string Private key (used for decryption and encryption)
- *
- * @return string The original string encrypted by the private key Result
- */
- function passport_encrypt($txt, $key) {
// Use random numbers to occur The processor generates values from 0 to 32000 and MD5()
- srand((double)microtime() * 1000000);
- $encrypt_key = md5(rand(0, 32000));
// Variable initialization
- $ctr = 0;
- $tmp = '';
// for loop, $i is an integer starting from 0 to less than the $txt string length
- for($ i = 0; $i < strlen($txt); $i++) {
- // If $ctr = the length of $encrypt_key, $ctr is cleared
- $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- // The $tmp string adds two digits at the end, the first content is the $ctr bit of $encrypt_key,
- // The second content is the $i-th bit of $txt and $encrypt_key $ctr bits are XORed. Then $ctr = $ctr + 1
- $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
- }
// Return the result, which is the base64 encoding result of the passport_key() function return value
- return base64_encode(passport_key($tmp, $key));
- }
- ?>
-
Copy code
if If you want to decrypt the encrypted content, you can refer to the passport decryption function written in PHP.
|