Refer to the php encryption and decryption processing class written by discuz passpor.
- /*---------------------------------------
- = Copyright agreement:
- = GPL (The gnu general public license Version 2, June 1991)
- = ------------------------------------------------------------
- = File name: cls. sys_crypt.php
- = Abstract: php encryption/decryption processing class
- = Version 1.0
- = Participation: passport related functions of the Discuz Forum
- = ------------------------------------------------------------
- = Script Written By PHPWMS project team
- = Last update: xinge
- = Last Date: 2007-12-09
- --------------------------------------- = */
-
- Class SysCrypt {
- Private $ crypt_key;
-
- // Constructor
- Public function _ construct ($ crypt_key ){
- $ This-> crypt_key = $ crypt_key;
- }
-
- Public function php_encrypt ($ txt ){
- Srand (double) microtime () * 1000000 );
- $ Encrypt_key = md5 (rand (0, 32000 ));
- $ Ctr = 0;
- $ Tmp = '';
- For ($ I = 0; $ I $ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
- $ Tmp. = $ encrypt_key [$ ctr]. ($ txt [$ I] ^ $ encrypt_key [$ ctr ++]);
- }
- Return base64_encode (self :__ key ($ tmp, $ this-> crypt_key ));
- }
-
- Public function php_decrypt ($ txt ){
- $ Txt = self ::__ key (base64_decode ($ txt), $ this-> crypt_key );
- $ Tmp = '';
- For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
- $ Md5 = $ txt [$ I];
- $ Tmp. = $ txt [++ $ I] ^ $ md5;
- }
- Return $ tmp;
- }
-
- Private function _ key ($ txt, $ encrypt_key ){
- $ Encrypt_key = md5 ($ encrypt_key );
- $ Ctr = 0;
- $ Tmp = '';
- For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
- $ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
- $ Tmp. = $ txt [$ I] ^ $ encrypt_key [$ ctr ++];
- }
- Return $ tmp;
- }
-
- Public function _ destruct (){
- $ This-> crypt_key = null;
- }
- }
-
- # -- Call example
- $ SC = new SysCrypt ('phpwms ');
- $ Text = '000000 ';
- Print ($ SC-> php_encrypt ($ text ));
- Print ('
');
- Print ($ SC-> php_decrypt ($ SC-> php_encrypt ($ text )));
- ?>
|