A simple package to encrypt Django's uploaded or downloading files
Python Makefile
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
djangoencryptfile
.gitignore
.travis.yml
Makefile
README.rst
license.txt
setup.cfg
setup.py
test_all.py

README.rst

Django File Encrypt

Build Status

image0

Code Health

This package can be used to encrypt Django’s in memory files to encrypt them.

Documentation

Go to this url: http://ruddra.com/2017/02/25/documentation-of-django-encrypt-file/

Download

Use pip install djangoencryptfile

Basic Usage:

from djangoencryptfile import EncryptionService
from django.core.files import File

password = '1234'
service = EncryptionService(raise_exception=False)

open('readme.md', 'rb') as inputfile:
    usefile = File(inputfile, name='readme.md')
    encrypted_file = service.encrypt_file(useFile, password, extension='enc')  # it will save readme.md.enc
    decrypt_file = service.decrypt_file(encrypted_file, password, extension='enc') # it will remove .enc extension

Using in Views:

from django_encrypt_file import EncryptionService, ValidationError


def some_view(request):
   try:
       myfile = request.FILES.get('myfile', None)
       password = request.POST.get('password', None)
       encrypted_file = EncryptionService().encrypt_file(myfile, password, extension='enc')
       decrypt_file = service.decrypt_file(encrypted_file, password, extension='enc') # it will remove .enc extension
   except ValidationError as e:
       print(e)

Input file here can be any kind of Django File Object like models.FileField or forms.FileFiled. raise_exception will throw ValidationError error which can be imported from django_encrypt_file import ValidationError