Django Encryption

Hello! Im getting a hard time understanding the encrypt() function in django. After using it in one of the fields in my model (so I could encrypt it), when I check it in the mysql server, a blob-randomnumber is shown. When I edit a certain record, I can be able to upload images.

Why does it show a random blob instead of non-readable text value?
And what type of encryption method used in this function? Is it fernet?

Sample model:
from django.db import models
from django_cryptography.fields import encrypt

class MyModel(models.Model):
name = models.CharField(max_length=120)
health_data = encrypt(models.DecimalField(max_length=100))

There is no function named encrypt defined in Django. That function would be coming from a third-party library - from your sample:

You’re using the encrypt function from the package django_cryptography (documentation)

Superficially, it looks like this supports different backends for encryption, so you can probably select from any number of algorithms. By default it does appear to use a Fernet algorithm.

Thank you for your immediate reply! :heart: So does it mean that the default algorithm of Fernet produces a blob file on the mysql server as encrypted value?

Also, do you know how can I use other algorithm (not the default one) under django-cryptography?

More accurately from a Python perspective, it’s a bytes object, but essentially yes.

Sorry, no. I can see in general how you might replace it, but not specifically how.

Thank you so much sir! :blush: