{"id":46795820,"url":"https://github.com/alpden550/encrypt-decrypt-fields","last_synced_at":"2026-03-10T04:11:48.427Z","repository":{"id":37394386,"uuid":"375630729","full_name":"alpden550/encrypt-decrypt-fields","owner":"alpden550","description":"Encrypt and decrypt fields for Django and SQLAlcemy.","archived":false,"fork":false,"pushed_at":"2024-04-15T22:53:34.000Z","size":268,"stargazers_count":11,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-13T19:52:15.740Z","etag":null,"topics":["cryptography","django","django-orm","encrypts","fernet","orm","python3","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alpden550.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-10T08:45:42.000Z","updated_at":"2024-08-07T08:38:56.000Z","dependencies_parsed_at":"2025-03-23T01:30:39.088Z","dependency_job_id":"da28b0e0-1b5d-4e35-abeb-dd15f799d818","html_url":"https://github.com/alpden550/encrypt-decrypt-fields","commit_stats":null,"previous_names":["alpden550/django-encrypt-decrypt"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/alpden550/encrypt-decrypt-fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpden550%2Fencrypt-decrypt-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpden550%2Fencrypt-decrypt-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpden550%2Fencrypt-decrypt-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpden550%2Fencrypt-decrypt-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alpden550","download_url":"https://codeload.github.com/alpden550/encrypt-decrypt-fields/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpden550%2Fencrypt-decrypt-fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30324187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T01:36:58.598Z","status":"online","status_checked_at":"2026-03-10T02:00:06.579Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","django","django-orm","encrypts","fernet","orm","python3","sqlalchemy"],"created_at":"2026-03-10T04:11:47.975Z","updated_at":"2026-03-10T04:11:48.415Z","avatar_url":"https://github.com/alpden550.png","language":"Python","readme":"# ORM Encrypt Decrypt Fields\n\nA Django and SQLAlchemy model field that encrypts your data based SHA256 algorithm and Fernet (symmetric encryption)\nwhen saving to the model field. The fernet module guarantees that data encrypted using it cannot be further manipulated\nor read without the key. It keeps data always encrypted in the database.\n\nAlso, possible to use it directly with the Crypto class.\n\n[![Check](https://github.com/alpden550/encrypt-decrypt-fields/actions/workflows/python-app.yml/badge.svg?branch=main)](https://github.com/alpden550/encrypt-decrypt-fields/actions/workflows/python-app.yml)\n\n## How install\n\n```\npip install encrypt-decrypt-fields\n```\n\n## Usage\n\nFor Django use project secret key or own:\n\n```python\nfrom django.db import models\nfrom encrypt_decrypt_fields import EncryptedBinaryField\n\n\nclass DemoModel(models.Model):\n    password = EncryptedBinaryField(blank=True, null=True)\n```\n\n```python\nfrom .models import DemoModel\n\nDemoModel.objects.create(password='password')\n\ndemo = DemoModel.objects.get(id=1)\nprint(demo.password.to_bytes()) \n# b'gAAAAABgxGVVeTPV9i1nPNl91Ss4XVH0rD6eJCgOWIOeRwtagp12gBJg9DL_HXODTDW0WKsqc8Z9vsuHUiAr3qQVE9YQmTd3pg=='\n```\n\nTo read bytes in postgres, use to_bytes() method of memoryview\n\n```\nobj.password.to_bytes()\n```\n\nor\n\n```\nbytes(obj.password, 'utf-8')\n```\n\nTo decrypt value use Crypto class:\n\n```python\nfrom django.conf import settings\nfrom encrypt_decrypt_fields import Crypto\nfrom .models import DemoModel\n\n\nobj = DemoModel.objects.get(id=1)\n\ndecrypted = Crypto(settings.SECRET_KEY).decrypt_token(obj.password.to_bytes())\nprint(decrypted) \n# 'password'\n```\n\nFor SQLAlchemy, it is similar:\n\n```python\nfrom sqlalchemy import Column, Integer, String\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.orm import declarative_base, sessionmaker\n\nfrom encrypt_decrypt_fields import Crypto, EncryptedAlchemyBinaryField\n\nBase = declarative_base()\nengine = create_engine(\"sqlite:///:memory:\", echo=True)\n\n\nclass Demo(Base):\n    __tablename__ = 'demo'\n\n    id = Column(Integer, primary_key=True)\n    name = Column(String)\n    password = Column(EncryptedAlchemyBinaryField(key='secret'), nullable=True)\n\n\nSession = sessionmaker(bind=engine)\nsession = Session()\n\ndemo = session.query(Demo).first()\nCrypto('secret').decrypt_token(demo.password)  \n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpden550%2Fencrypt-decrypt-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falpden550%2Fencrypt-decrypt-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpden550%2Fencrypt-decrypt-fields/lists"}