Encrypt files uploaded to a Django application.
Project description
Django Encrypted Files
Encrypt files uploaded to your Django application.
This package uses AES in CTR mode to encrypt files via an upload handler.
The upload handler encrypts data as it is recieved during upload, so only encrypted data is ever written to temporary files.
Usage
Add the encrypted_files
app to your INSTALLED_APPS
setting:
settings.py
INSTALLED_APPS = [
...
'encrypted_files',
...
]
Add an encryption key to use. This should be 16, 24, or 32 bytes long:
settings.py
AES_KEY = b'\x1a>\xf8\xcd\xe2\x8e_~V\x14\x98\xc2\x1f\xf9\xea\xf8\xd7c\xb3`!d\xd4\xe3+\xf7Q\x83\xb5~\x8f\xdd'
If you want to encrypt ALL uploaded files, add the EncryptedFileUploadHandler
as the first handler:
settings.py
FILE_UPLOAD_HANDLERS = [
"encrypted_files.uploadhandler.EncryptedFileUploadHandler",
"django.core.files.uploadhandler.MemoryFileUploadHandler",
"django.core.files.uploadhandler.TemporaryFileUploadHandler"
]
Use regular FileFields for file uploads. When you want to decrypt the file, use the EncryptedFile
helper class
views.py
from .models import ModelWithFile
from encrypted_files.base import EncryptedFile as EF
from django.http import HttpResponse
def decrypted(request,pk):
f = ModelWithFile.objects.get(pk=pk).file
ef = EF(f)
return HttpResponse(ef.read())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_encrypted_files-0.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6ad72ed2c0ab841014e725ce98f4dcd44f789ac0c618039bf10ff2324aa0b7 |
|
MD5 | 947d5185b6d1404b3ca675a54015a920 |
|
BLAKE2b-256 | 7a514011204a2d8524cb0f8a76c33c67b2e2dd7c8fa4c42216610fe3bfd4341b |
Hashes for django_encrypted_files-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f7ae89729307605d090ee1b56eac97843141e87077aaa32d95d01502eb023b |
|
MD5 | 647d414aac458e2752fc551955250675 |
|
BLAKE2b-256 | 4f8b64cba002e40f6bd1f20c240c093c56eb38defe20e163ca5a62510b175975 |