Skip to main content

Advanced encryption protecting your python codebase.

Project description

SOURCEdefender - advanced encryption protecting your Python codebase


python downloads downloads

SOURCEdefender can protect your plaintext Python source code with AES 256-bit Encryption. There is no impact on the performance of your running application as the decryption process takes place during the import of your module or when loading your script on the command-line. Encrypted code won't run any slower once loaded from a .pye file compared to loading from a .py or .pyc file.

We hook directly into the import process so there are no cross platform or Python version compatibility issues. Encrypted code will run on the ANY target environment we support. Obviously your code needs to be written with the target platform in mind, we can't automagically make sys.getwindowsversion() work on Linux.

Features

  • Code encrypted with AES 256-bit encryption.
  • Encrypted code will load on ANY supported environment.
  • Enforced expire time on encrypted code (optional).

Supported Environments

Architecture Operating System Python 3.6 Python 3.7 Python 3.8 Python 3.9
X86_64 Windows Y Y Y Y
X86_64 Linux Y Y Y Y
X86_64 macOS Y Y Y Y
ARM64 macOS N/A N/A N/A Y
ARMv6 Linux Y Y Y Y
ARMv7 Linux Y Y Y Y

Licence

You can distribute the sourcedefender module with any project, commercial or otherwise. However, the purchase of a license is required for the distribution of encrypted code that will be used in a commercial offering. You do not need to purchase a subscription for use in a Personal or a FOSS project. However, we would greatly appreciate that you document the usage of SOURCEdefender on your website, documentation, and in your source code. Please link back to this page where you can.

Enterprise Subscription & Support

To create encrypted code for distribution in a commercial offering we require you to have an active subscription in place. The subscription is a rolling contract and gives you permission to create encrypted code for distribution and gain access to priority email support. Should you decide to cancel your subscription you would be free to distribute any previously encrypted code, but you would not be able to make changes to existing files or create new ones for deploying a new feature, a bug fix, or a hot-patch.

Enterprise Only Features

  • Custom encryption/decryption salt to ensure that nobody but the licensed user can run the code. This salt setting is required to be the same for encrypting and decrypting code. The salt can be the same for all files encrypted, or unique to each a single file. Even if you provide the same salt for encrypting all your files we do not use the exact same salt for each file we encrypt, so no two files will ever have the same salt used.

  • Download .pye files from a URL. The encrypted file is downloaded and imported as a normal Python module.

If you are an enterprise subscriber please contact us regarding these features feature.

Subscription Plans

The subscription is valid for your whole organisation and not for a set person or machine.

  • Monthly Subscription: £50.
  • Annual Subscription (Saving 20%!): £500.
  • All prices exclude VAT charged at 20%. VAT may be subject to change depending on your country of residence.

Payment Options: The above links on this page take you to PayPal to manage the subscription payments.

Our Sponsors

We are immensely grateful to the following organisations:

If you would like to help sponsor future development of this package then please send us an email.

Usage

How do I protect my Python source code?

Let's have a look at an example of the encryption process:

$ cat /home/ubuntu/helloworld.py
print("Hello World!")

This is a very basic example and produces the following output:

$ python3 /home/ubuntu/helloworld.py
Hello World!

We do not want anyone to get at our source code and we also don't want anyone to run this code after 1 day. When we encrypt the file we can enforce an expire time of 1 day from now with the --ttl option and we can remove the plaintext .py file after encryption by adding the --remove option. We suggest doing this otherwise you may accidentially distribute the plaintext file alongside the encrypted one.

The test command we are using is as follows:

$ sourcedefender encrypt --remove --ttl=1d /home/ubuntu/helloworld.py
SOURCEdefender v6.0.50

Processing:

/home/ubuntu/helloworld.py

Now the file is encrypted, its contents are as follows:

$ cat /home/ubuntu/helloworld.pye
-----BEGIN SOURCEDEFENDER FILE -----
Version : 6.0.50

Y3YzejdSVyg9eD42Ozg4mmpBDbsL/MRC8cpX5XSKZGHz+1Okwrjw1o65m3zXSs41K3dHWGNpWWNs
QmVjKk5TT1VSQ0VERUZFTkRFUjKN9Hmoy2/DLeDvybmHKY1NOoZ7OZhRZkI1M5f619cekYIh31AV
8mAKvnFKU09VUkNFREVGRU5ERVJtZVY1TSsrRHJYQSZhej7jYt+N4Lbsf/9Q05Xlzm2SOFB0N3tS
Xk53QW9OYmtu

------END SOURCEDEFENDER FILE ------

Once a file has been encrypted, its extension is changed .py to .pye, this is so the module knows its encrypted and can process it accordingly during import. All you need to remember is to inlcude sourcedefender as a dependency while packaging your project and import the sourcedefender module before you attempt to use your encrypted code.

Can I still run Python from the command-line?

Yes, you can still run scripts from the command-line, but you need to run the sourcedefender library module, and include your encrypted file name as the first argument:

$ python3 -m sourcedefender /home/ubuntu/helloworld.pye
Hello World!
$

However, due to the way Python works, and the fact that we need to run the 'sourcedefender' library module as a script, we are unable to set '__name__' to '__main__' when running scripts from the command line. This means that if you use this in your code:

if __name__ is '__main__':

then it won't be executed. You will need to make allowances for that.

Importing packages & modules

The usual import system can also be used:

$ cd /home/ubuntu
$ ls
helloworld.pye
$ python3
>>>
>>> import sourcedefender
>>> import helloworld
Hello World!
>>> exit()
$

Integrating encrypted code with PyInstaller

PyInstaller scans your code for import statements so it knows what packages to freeze. This scanning is not possible inside encrypted code so you need to tell PyInstaller to include your encrypted files. For this example, we have the following project structure:

pyexe.py
lib
├── fibonacci.pye
└── fib.pye

In our executable script "pyexe.py" we have the following code:

$ cat pyexe.py
import sourcedefender
import fib

To ensure that PyInstaller includes our encrypted files, we need to tell it where they are with the --add-binary option. So, for the above project, we could use this command:

$ pyinstaller --onefile --add-binary lib:. pyexe.py

If you have imports that are not in your lib folder or you are using modules imported inside your encrypted codebase then the pyinstaller won't be able to detect these. To get round this, you can use the '--hidden-import' option to include them in your final build such as this:

$ pyinstaller --onefile --add-binary lib:. --hidden-import mylib pyexe.py

Legal

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. REVERSE ENGINEERING IS STRICTLY PROHIBITED.

SOURCEdefender is operated by RS474 Limited, a company registered in the United Kingdom. Company Registration No: 12865773. VAT Registration No: GB357943163. The goods and services you order via this page purchased from RS474 Limited.

Copyright 2018-2021 SOURCEdefender. All rights reserved.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sourcedefender, version 6.0.50
Filename, size File type Python version Upload date Hashes
Filename, size sourcedefender-6.0.50.tar.gz (4.4 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page