
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
encrypt-decrypt-fields
Advanced tools
Encrypt and decrypt fields for a Django, SQLAlchemy ORM models or for direct use Crypto class
A Django and SQLAlchemy model field that encrypts your data based SHA256 algorithm and Fernet (symmetric encryption) when saving to the model field. The fernet module guarantees that data encrypted using it cannot be further manipulated or read without the key. It keeps data always encrypted in the database.
Also, possible to use it directly with the Crypto class.
pip install encrypt-decrypt-fields
For Django use a project secret key or own:
from django.db import models
from encrypt_decrypt_fields import EncryptedBinaryField
class DemoModel(models.Model):
password = EncryptedBinaryField(blank=True, null=True)
from .models import DemoModel
DemoModel.objects.create(password='password')
demo = DemoModel.objects.get(id=1)
print(demo.password)
# b'gAAAAABgxGVVeTPV9i1nPNl91Ss4XVH0rD6eJCgOWIOeRwtagp12gBJg9DL_HXODTDW0WKsqc8Z9vsuHUiAr3qQVE9YQmTd3pg=='
To decrypt a value, use Crypto class:
from django.conf import settings
from encrypt_decrypt_fields import Crypto
from .models import DemoModel
obj = DemoModel.objects.get(id=1)
service = Crypto(settings.SECRET_KEY)
decrypted = service.decrypt_token(obj.password)
print(decrypted)
# 'password'
For SQLAlchemy, it is similar:
from sqlalchemy import Column, Integer, String
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
from encrypt_decrypt_fields import Crypto, EncryptedAlchemyBinaryField
Base = declarative_base()
engine = create_engine("sqlite:///:memory:", echo=True)
class Demo(Base):
__tablename__ = 'demo'
id = Column(Integer, primary_key=True)
name = Column(String)
password = Column(EncryptedAlchemyBinaryField(key='secret'), nullable=True)
Session = sessionmaker(bind=engine)
session = Session()
demo = session.query(Demo).first()
Crypto('secret').decrypt_token(demo.password)
FAQs
Encrypt and decrypt fields for a Django, SQLAlchemy ORM models or for direct use Crypto class
We found that encrypt-decrypt-fields demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.