Php encryption/decryption
-
- 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;
- }
- }
-
-
- $ SC = new SysCrypt ('phpwms ');
- $ Text = '000000 ';
- Print ($ SC-> php_encrypt ($ text ));
- Print ('
');
- Print ($ SC-> php_decrypt ($ SC-> php_encrypt ($ text )));
- ?>
|
Encryption and decryption, php