Skip to content

A simple package to encrypt Django's uploaded or downloading files

License

Notifications You must be signed in to change notification settings

ruddra/django-encrypt-file

Repository files navigation

Django File Encrypt

Build Status

image0

Code Health

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

Status

This package is no longer maintained. So use at your own risk.

Documentation

Go to this url: https://ruddra.com/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