Refer to the php encryption and decryption processing class written by discuz passpor.

Source: Internet
Author: User
Refer to the php encryption and decryption processing class written by discuz passpor.

  1. /*---------------------------------------
  2. = Copyright agreement:
  3. = GPL (The gnu general public license Version 2, June 1991)
  4. = ------------------------------------------------------------
  5. = File name: cls. sys_crypt.php
  6. = Abstract: php encryption/decryption processing class
  7. = Version 1.0
  8. = Participation: passport related functions of the Discuz Forum
  9. = ------------------------------------------------------------
  10. = Script Written By PHPWMS project team
  11. = Last update: xinge
  12. = Last Date: 2007-12-09
  13. --------------------------------------- = */
  14. Class SysCrypt {
  15. Private $ crypt_key;
  16. // Constructor
  17. Public function _ construct ($ crypt_key ){
  18. $ This-> crypt_key = $ crypt_key;
  19. }
  20. Public function php_encrypt ($ txt ){
  21. Srand (double) microtime () * 1000000 );
  22. $ Encrypt_key = md5 (rand (0, 32000 ));
  23. $ Ctr = 0;
  24. $ Tmp = '';
  25. For ($ I = 0; $ I $ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
  26. $ Tmp. = $ encrypt_key [$ ctr]. ($ txt [$ I] ^ $ encrypt_key [$ ctr ++]);
  27. }
  28. Return base64_encode (self :__ key ($ tmp, $ this-> crypt_key ));
  29. }
  30. Public function php_decrypt ($ txt ){
  31. $ Txt = self ::__ key (base64_decode ($ txt), $ this-> crypt_key );
  32. $ Tmp = '';
  33. For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
  34. $ Md5 = $ txt [$ I];
  35. $ Tmp. = $ txt [++ $ I] ^ $ md5;
  36. }
  37. Return $ tmp;
  38. }
  39. Private function _ key ($ txt, $ encrypt_key ){
  40. $ Encrypt_key = md5 ($ encrypt_key );
  41. $ Ctr = 0;
  42. $ Tmp = '';
  43. For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
  44. $ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
  45. $ Tmp. = $ txt [$ I] ^ $ encrypt_key [$ ctr ++];
  46. }
  47. Return $ tmp;
  48. }
  49. Public function _ destruct (){
  50. $ This-> crypt_key = null;
  51. }
  52. }
  53. # -- Call example
  54. $ SC = new SysCrypt ('phpwms ');
  55. $ Text = '000000 ';
  56. Print ($ SC-> php_encrypt ($ text ));
  57. Print ('
    ');
  58. Print ($ SC-> php_decrypt ($ SC-> php_encrypt ($ text )));
  59. ?>

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.