This project is created to tinker a method to encrypt the source code of a PHP project in NativePHP packages.
It has 2 files, encrypt.php
and libnativephp_crypt.so
:
-
The
libnativephp_crypt.so
is a PHP extension that basically has two methods:nativephp_crypt
andnativephp_decrypt
which are used to encrypt and decrypt the source code respectively. It is written in Rust withext-php-rs
. It gets the encryption key from the environment variableNATIVEPHP_CRYPT_KEY
in build time. -
The
encrypt.php
is an example script that encrypts allphp
andblade.php
files in the source code withnativephp_crypt
and replaces them with a file that contains php code which decodes the encrypted code withnativephp_decrypt()
method.
- Clone this repository
git clone alperenersoy/nativephp-encryption-test
- Create a new Laravel project
composer create-project laravel/laravel
- Copy
encrypt.php
to the root of the Laravel project
cp encrypt.php ./laravel/encrypt.php
- Run
encrypt.php
with the extension
php -d extension=./libnativephp_crypt.so ./laravel/encrypt.php
- Serve the Laravel project with the extension
php -d extension=./libnativephp_crypt.so -S 127.0.0.1:8080 ./laravel/public/index.php
- The extension built with
ext-php-rs
is too big. I guess the nativeC
version of the extension will be smaller. It is a big problem for NativePHP packages since they are supposed to be small. - The extension should be built in the build time of the package to provide different keys for different applications.
- You can easily add
dd(nativephp_decrypt($path));
to the replacement files to see the decrypted code. The extension should be able to detect if replacement files has been modified and should not decrypt the code if they are modified.