Skip to main content

pysqlcrypt

Python implementation of SQL Server's ENCRYPTBYPASSPHRASE and DECRYPTBYPASSPHRASE functions.

Quick Start

pip install pysqlcrypt
from pysqlcrypt import encrypt_by_passphrase, decrypt_by_passphrase, SQLCryptVersion

# Encrypt
ciphertext = encrypt_by_passphrase("passphrase", "plaintext", SQLCryptVersion.V2)

# Decrypt with auto-detection (recommended)
plaintext = decrypt_by_passphrase("passphrase", ciphertext, encoding="auto")

API

encrypt_by_passphrase(passphrase, plaintext, version=V1, authenticator=None, *, encoding="utf-8")

Returns encrypted bytes. Use SQLCryptVersion.V1 for SQL Server 2008-2016, SQLCryptVersion.V2 for 2017+.

decrypt_by_passphrase(passphrase, ciphertext, *, authenticator=None, encoding=None)

Returns decrypted bytes, or str if encoding is specified. Accepts bytes or hex string (with or without 0x prefix).

Encoding Options

Value Behavior
None Returns raw bytes
"auto" Auto-detects UTF-16LE (NVARCHAR) vs UTF-8
"utf-8" Decodes as UTF-8 (VARCHAR)
"utf-16-le" Decodes as UTF-16LE (NVARCHAR)

Version Reference

Version SQL Server Algorithm
V1 2008-2016 3DES-CBC, SHA1
V2 2017+ AES-256-CBC, SHA256

Notes

  • Use encoding="auto" for mixed VARCHAR/NVARCHAR data
  • The authenticator parameter embeds additional context data for verification
  • Decryption auto-detects the version from the ciphertext header

License

MIT

🍌

Release files for pysqlcrypt 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysqlcrypt 0.2.0
File Size Uploaded
pysqlcrypt-0.2.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysqlcrypt 0.2.0
File Interpreter ABI Platform
pysqlcrypt-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / pysqlcrypt-0.2.0.tar.gz

Download URL pysqlcrypt-0.2.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9aa211fbabdd6fc92c20f3aa8ee43b2388692ba58c9296913a96528393c1e505
BLAKE2b-256 checksum
How to use checksums
13f24a9130b7fc19aca933b19cf20ea9f781b8769a9e0e13274440ba9f9de1d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Release files / pysqlcrypt-0.2.0-py3-none-any.whl

Download URL pysqlcrypt-0.2.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e34ccd4b8cbc378c94211afbe9518b7e2fa5ce7541580b12161d44efd3a12b26
BLAKE2b-256 checksum
How to use checksums
b1594065017a8a4c50304cf31500aa555654dd2aba155ab3eae55ea6a95737f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page