Coder Social home page Coder Social logo

nativephp-encryption-test's Introduction

NativePHP Source Code Encryption Test

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 and nativephp_decrypt which are used to encrypt and decrypt the source code respectively. It is written in Rust with ext-php-rs. It gets the encryption key from the environment variable NATIVEPHP_CRYPT_KEY in build time.

  • The encrypt.php is an example script that encrypts all php and blade.php files in the source code with nativephp_crypt and replaces them with a file that contains php code which decodes the encrypted code with nativephp_decrypt() method.

How to test

  1. Clone this repository
git clone alperenersoy/nativephp-encryption-test
  1. Create a new Laravel project
composer create-project laravel/laravel    
  1. Copy encrypt.php to the root of the Laravel project
cp encrypt.php ./laravel/encrypt.php
  1. Run encrypt.php with the extension
php -d extension=./libnativephp_crypt.so ./laravel/encrypt.php
  1. Serve the Laravel project with the extension
php -d extension=./libnativephp_crypt.so -S 127.0.0.1:8080 ./laravel/public/index.php

Things to improve

  • The extension built with ext-php-rs is too big. I guess the native C 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.