Passport encryption function written in php

WBOY
Release: 2016-07-25 09:07:21
Original
828 people have browsed it
  1. /**

  2. * Passport encryption function
  3. *
  4. * @param string The original string waiting to be encrypted
  5. * @param string Private key (used for decryption and encryption)
  6. *
  7. * @return string The original string encrypted by the private key Result
  8. */
  9. function passport_encrypt($txt, $key) {

  10. // Use random numbers to occur The processor generates values ​​from 0 to 32000 and MD5()

  11. srand((double)microtime() * 1000000);
  12. $encrypt_key = md5(rand(0, 32000));

  13. // Variable initialization

  14. $ctr = 0;
  15. $tmp = '';

  16. // for loop, $i is an integer starting from 0 to less than the $txt string length

  17. for($ i = 0; $i < strlen($txt); $i++) {
  18. // If $ctr = the length of $encrypt_key, $ctr is cleared
  19. $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  20. // The $tmp string adds two digits at the end, the first content is the $ctr bit of $encrypt_key,
  21. // The second content is the $i-th bit of $txt and $encrypt_key $ctr bits are XORed. Then $ctr = $ctr + 1
  22. $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
  23. }

  24. // Return the result, which is the base64 encoding result of the passport_key() function return value

  25. return base64_encode(passport_key($tmp, $key));
  26. }
  27. ?>

Copy code

if If you want to decrypt the encrypted content, you can refer to the passport decryption function written in PHP.



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!