Thursday, June 3. 2004
Back in Vancouver I first brought up the usefulness of a PHP extension which ran encrypted PHP scripts transparently as part of what was then called the philter extension. Since then, I have moved away from the philter extension and taken my work in a more focused direction. Today the public gets its first glance at this work with the alpha release of the
BLENC extension in the PHP
PECL Repository. To my knowledge this alpha should work on versions of PHP 4.3.0+ and higher, although honestly it was only tested in PHP 5.0 RC3. Using BLENC is really simple, as it only has one function:
blenc_encrypt($input_data, $output_file [, $key]);
The
$input_data parameter is a string representing the data to encode (in general this would be a PHP script loaded using the
file_get_contents function). The
$output_file parameter is the filename to write the encrypted script to (i.e. myscript.phpe), and the third optional parameter
$key is the key to encrypt the PHP script with. If no key is provided, a random one will be generated.
Once an encrypted PHP script has been generated, the key to decrypt it must be stored in the key file in order for the PHP script to be executed. These keys are stored in the text file specified by the
blenc.key_file php.ini
configuration directive (one per line, default
/usr/local/etc/blenckeys).
Assuming you have a valid decryption key in your key file, the PHP script will execute as if it was any other PHP script. However, if you do not have a valid decryption key you will receieve a message such as the following:
Fatal error: Validation of script 'encrypted.phpe' failed, cannot execute.
Let me know if there are any problems using it! Have fun!