Home arrow PHP arrow Page 3 - PHP Encryption and Decryption Methods

PHP Eval Function in Encoding Methods - PHP

PHP encryption is a method of obfuscating scripts in such a way that it offers additional protection and prevents unauthorized editing of the scripts. This article discusses both encryption and decryption.

TABLE OF CONTENTS:
  1. PHP Encryption and Decryption Methods
  2. Base 64 Encoding and Compression/Decompression Techniques
  3. PHP Eval Function in Encoding Methods
  4. Case Example: Encoding a Working PHP Script
By: Codex-M
Rating: starstarstarstarstar / 13
November 03, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Since the encrypted output is a string (after applying compression and base 64 encoding techniques), we need to tell PHP that the encoded string is indeed a script. To do this, we need to use the eval() function in PHP. The purpose of this function is to evaluate a string as a PHP code; you can research the details of the eval() function on your own.

The standard encoded PHP script (encrypted) takes a form similar to this example:

<?php eval(gzinflate(base64_decode('FZfHDoTYEUV/ZXYzIxbkJFseAU1qcg4bi9TknPl64z0SUK/evef8859///
NHcSTdX+VTD78u2Yq/0mQtCOyA7YSRf3y'))); ?>

To encode the PHP script into the above form, we will utilize the steps below:

Step 1: Capture the PHP script to be encoded and convert it to a string, except for the PHP tags (<?php and ?>)

Step 2: Compress the string using the gzdeflate function (using the maximum compression level) and assign the compressed string to a PHP variable.

Step 3: Encode the compressed string using base 64 encoding and assign the encoded string to a PHP variable.

Step 4: To let PHP interpret/parse correctly the encoded scripts, append the decoding, decompression and use eval functions, as shown below:

<?php

eval(gzinflate(base64_decode(‘This is the encoded and compressed PHP script strings except the start <?php and end tags ?>’)));

?>



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap

Dev Shed Tutorial Topics: