# Django Encryption

**URL:** <https://forum.djangoproject.com/t/django-encryption/17419>\
**Category:** Using the ORM\
**Created:** [December 3, 2022, 3:40pm UTC](https://forum.djangoproject.com/t/django-encryption/17419 "2022-12-03T15:40:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielle006](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/danielle006/32/11165_2.png) [@danielle006](https://forum.djangoproject.com/u/danielle006)\
**Post date:** [December 3, 2022, 3:40pm UTC](https://forum.djangoproject.com/t/django-encryption/17419/1 "2022-12-03T15:40:09Z")

</div>

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))

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 3, 2022, 4:02pm UTC](https://forum.djangoproject.com/t/django-encryption/17419/2 "2022-12-03T16:02:35Z")

</div>

> [@danielle006](#):
>
> Im getting a hard time understanding the encrypt() function in django.

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

> [@danielle006](#):
>
> from django\_cryptography.fields import encrypt

You’re using the encrypt function from the package [`django_cryptography`](https://github.com/georgemarshall/django-cryptography) ([documentation](https://django-cryptography.readthedocs.io/en/latest/))

Superficially, it looks like this supports different backends for encryption, so you can probably select from any number of algorithms. [By default](https://github.com/georgemarshall/django-cryptography/blob/d31005f35284fee9beebac377b34d9f072936626/django_cryptography/fields.py#L84) it does appear to use a [Fernet](https://github.com/georgemarshall/django-cryptography/blob/d31005f35284fee9beebac377b34d9f072936626/django_cryptography/utils/crypto.py#L121) algorithm.

---

<div class="post-metadata">

**Author:** ![danielle006](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/danielle006/32/11165_2.png) [@danielle006](https://forum.djangoproject.com/u/danielle006)\
**Post date:** [December 4, 2022, 2:04am UTC](https://forum.djangoproject.com/t/django-encryption/17419/3 "2022-12-04T02:04:02Z")

</div>

Thank you for your immediate reply! ❤ 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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/9/917a1ff017b7631769d873a9bcbaa31f31288489.jpeg)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 4, 2022, 3:02am UTC](https://forum.djangoproject.com/t/django-encryption/17419/4 "2022-12-04T03:02:20Z")

</div>

> [@danielle006](#):
>
> So does it mean that the default algorithm of Fernet produces a blob file on the mysql server as encrypted value?

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

> [@danielle006](#):
>
> Also, do you know how can I use other algorithm (not the default one) under django-cryptography?

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

---

<div class="post-metadata">

**Author:** ![danielle006](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/danielle006/32/11165_2.png) [@danielle006](https://forum.djangoproject.com/u/danielle006)\
**Post date:** [December 4, 2022, 3:45am UTC](https://forum.djangoproject.com/t/django-encryption/17419/5 "2022-12-04T03:45:58Z")

</div>

Thank you so much sir! 😊
