How to encrypt files for email delivery in Django on Ubuntu server

I need to set up file encryption in my Django application that runs on Ubuntu. The goal is to send encrypted files through email to users while making sure the data stays secure during transmission.

The main requirements are:

  • Files should be encrypted before sending via email
  • Third parties cannot read the content if they intercept the email
  • Users need a password to decrypt (password sent through different channel)
  • Recipients using Windows or Mac should be able to decrypt easily

What encryption methods work best for this use case in Django? Are there any specific libraries or tools that handle this kind of file encryption on Ubuntu that would be compatible with standard desktop systems?

have you thought about using GPG for encrypting files? it’s pretty effective on Ubuntu and works well on both Windows and Mac. just curious, what kind of files are you dealing with? and how do you plan to send the emails, through Django directly or something like Celery?

password-protected zip files are probably the easiest bet. python’s zipfile module handles aes encryption, and anyone can open them with built-in tools on windows or mac - no special software needed. just create a random password, zip your file, and send the password separately.

I used the cryptography library with Fernet encryption for this. Works great because Fernet creates symmetric keys that are URL-safe, and you can decrypt the files on any platform with Python or compatible tools. In my Django project, I built a service that encrypts files before emailing them, then sends the decryption key through SMS or a different email. Recipients just use a simple Python script or online Fernet tools to open their files. Way easier than GPG for non-technical users, and you get full control over encryption in your Django app without dealing with external key management.