This article introduces two methods to encrypt the php program itself. Our common method is base64_encode (gzdeflate ($ contents, the second method is rare. For more information, see.
Instance 1
The Code is as follows: |
Copy code |
<? Php Function encode_file_contents ($ filename ){ $ Type = strtolower (substr (strrchr ($ filename, '.'), 1 )); If ('php' = $ type & is_file ($ filename) & is_writable ($ filename) {// compress the Code if the php file is writable. $ Contents = file_get_contents ($ filename); // checks whether the file has been encoded. $ Contents = php_strip_whitespace ($ filename ); // Remove the PHP header and tail identifiers $ HeaderPos = strpos ($ contents, '<? Php '); $ FooterPos = strrpos ($ contents, '?> '); $ Contents = substr ($ contents, $ headerPos + 5, $ footerPos-$ headerPos ); $ Encode = base64_encode (gzdeflate ($ contents); // start Encoding $ Encode = '<? Php '. "n eval (gzinflate (base64_decode (". "'". $ encode. "'". "); nn?> "; Return file_put_contents ($ filename, $ encode ); } Return false; } // Call a function $ Filename = 'dam. php '; Encode_file_contents ($ filename ); Echo "OK, encryption complete! " ?> |
Instance 2
The Code is as follows: |
Copy code |
<? Php Function RandAbc ($ length = "") {// returns a random string $ Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "; Return str_shuffle ($ str ); } $ Filename = 'dam. php '; $ T_k1 = RandAbc (); // random key 1 $ T_k2 = RandAbc (); // random key 2 $ Vstr = file_get_contents ($ filename); // the object to be encrypted $ V1 = base64_encode ($ vstr ); $ C = strtr ($ v1, $ T_k1, $ T_k2); // replace the corresponding character with the key. $ C = $ T_k1. $ T_k2. $ c; $ Q1 = "O00O0O "; $ Q2 = "O0O000 "; $ Q3 = "O0OO00 "; $ Q4 = "OO0O00 "; $ Q5 = "OO0000 "; $ Q6 = "O00OO0 "; $ S = '$ '. $ q6. '= urldecode ("% 6E1% 7A % 62% 2F % 6D % 615% 5C % 76% 740% 6928% 2D % 70% 78% 75% 71% 2A6% 6C % 79% 6B % 72% 5F % 65% 68% 63% 73% 77% 6F4% 2B % 6637% 6A "); $ '. $ q1. '= $ '. $ q6. '{3 }. $ '. $ q6. '{6 }. $ '. $ q6. '{33 }. $ '. $ q6. '{30}; $ '. $ q3. '= $ '. $ q6. '{33 }. $ '. $ q6. '{10 }. $ '. $ q6. '{24 }. $ '. $ q6. '{10 }. $ '. $ q6. '{24}; $ '. $ q4. '= $ '. $ q3. '{0 }. $ '. $ q6. '{18 }. $ '. $ q6. '{3 }. $ '. $ q3. '{0 }. $ '. $ q3. '{1 }. $ '. $ q6. '{24}; $ '. $ q5. '= $ '. $ q6. '{7 }. $ '. $ q6. '{13}; $ '. $ q1 .'. = $ '. $ q6 .' {22 }. $ '. $ q6. '{36 }. $ '. $ q6. '{29 }. $ '. $ q6. '{26 }. $ '. $ q6. '{30 }. $ '. $ q6. '{32 }. $ '. $ q6. '{35 }. $ '. $ q6. '{26 }. $ '. $ q6. '{30}; eval ($ '. $ q1 .'("'. base64_encode ('$ '. $ q2. '= "'. $ c. '"; eval ('?> '. $ '. $ Q1. '($ '. $ q3. '($ '. $ q4. '($ '. $ q2. ', $ '. $ q5. '* 2), $ '. $ q4. '($ '. $ q2. ', $ '. $ q5. ', $ '. $ q5. '), $ '. $ q4. '($ '. $ q2. ', 0, $ '. $ q5 .'))));'). '"));'; $ S = '<? Php '. $ S. ' ?> '; Echo "OK, encryption complete! "; // Generate the encrypted PHP File $ Fpp1 = fopen ('dam. php', 'w '); Fwrite ($ fpp1, $ s) or die ('file writing error '); ?> |