PHP Cryptographic decryption Processing class

Source: Internet
Author: User
Tags crypt
  1. Class Syscrypt {
  2. Private $crypt _key;
  3. constructor function
  4. Public function __construct ($crypt _key) {
  5. $this-Crypt_key = $crypt _key;
  6. }
  7. Public Function Php_encrypt ($txt) {
  8. Srand (Double) microtime () * 1000000);
  9. $encrypt _key = MD5 (rand (0,32000));
  10. $ctr = 0;
  11. $tmp = ";
  12. for ($i = 0; $i
  13. $ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
  14. $tmp. = $encrypt _key[$ctr]. ($txt [$i]^ $encrypt _key[$ctr + +]);
  15. }
  16. Return Base64_encode (Self::__key ($tmp, $this-Crypt_key));
  17. }
  18. Public Function Php_decrypt ($txt) {
  19. $txt = Self::__key (Base64_decode ($txt), $this-Crypt_key);
  20. $tmp = ";
  21. for ($i = 0; $i < strlen ($txt); $i + +) {
  22. $MD 5 = $txt [$i];
  23. $tmp. = $txt [+ + $i] ^ $MD 5;
  24. }
  25. return $tmp;
  26. }
  27. Private Function __key ($txt, $encrypt _key) {
  28. $encrypt _key = MD5 ($encrypt _key);
  29. $ctr = 0;
  30. $tmp = ";
  31. for ($i = 0; $i < strlen ($txt); $i + +) {
  32. $ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
  33. $tmp. = $txt [$i] ^ $encrypt _key[$ctr + +];
  34. }
  35. return $tmp;
  36. }
  37. Public Function __destruct () {
  38. $this-crypt_key = null;
  39. }
  40. }
  41. $SC = new Syscrypt (' phpwms ');
  42. $text = ' 110 ';
  43. Print ($SC-Php_encrypt ($text));
  44. Print ('
    ');
  45. Print ($SC-Php_decrypt ($SC-Php_encrypt ($text)));
  46. ?>
Copy Code
Encrypted decryption, PHP
  • 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.