ORM Encrypt Decrypt Fields
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.
How install
pip install encrypt-decrypt-fields
Usage
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)
Metadata
Release files for encrypt-decrypt-fields 1.3.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| encrypt_decrypt_fields-1.3.8.tar.gz | 4.8 kB | Without provenance | Details for encrypt_decrypt_fields-1.3.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| encrypt_decrypt_fields-1.3.8-py3-none-any.whl | Python 3 | none | any | Details for encrypt_decrypt_fields-1.3.8-py3-none-any.whl |
Total release size: 12.0 kB
Release files / encrypt_decrypt_fields-1.3.8.tar.gz
| Download URL | encrypt_decrypt_fields-1.3.8.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71a732bdc389ecdb37fe41718edd8e9fb9654ec2c646633e8e1683ae0b2828e3
|
|
BLAKE2b-256 checksum How to use checksums |
e92e9cbac2c693811e146c44fb2da0dee2a9a590f2bc164215dd9b6c00d2701a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.9 Darwin/24.6.0
|
Release files / encrypt_decrypt_fields-1.3.8-py3-none-any.whl
| Download URL | encrypt_decrypt_fields-1.3.8-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
75280a2b50f00357954aeeb0b6fb3559c4cb8ddc88bfba0ed6ea62669b29649f
|
|
BLAKE2b-256 checksum How to use checksums |
1ee92e0d77994cef338b078adf266be86a4be75dcf512304e144e8a5b1499b8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.9 Darwin/24.6.0
|
Security for encrypt-decrypt-fields 1.3.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.