Skip to main content

Python implementation of SQL Server's ENCRYPTBYPASSPHRASE and DECRYPTBYPASSPHRASE

Project description

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

🍌

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysqlcrypt-0.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysqlcrypt-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pysqlcrypt-0.2.0.tar.gz.

File metadata

  • Download URL: pysqlcrypt-0.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysqlcrypt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9aa211fbabdd6fc92c20f3aa8ee43b2388692ba58c9296913a96528393c1e505
MD5 dde31e724a8b96c72d659ebebd4780ab
BLAKE2b-256 13f24a9130b7fc19aca933b19cf20ea9f781b8769a9e0e13274440ba9f9de1d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysqlcrypt-0.2.0.tar.gz:

Publisher: publish.yml on ivan-loh/pysqlcrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysqlcrypt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pysqlcrypt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysqlcrypt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e34ccd4b8cbc378c94211afbe9518b7e2fa5ce7541580b12161d44efd3a12b26
MD5 ae346df099afa241e8ed64d01ad70ad2
BLAKE2b-256 b1594065017a8a4c50304cf31500aa555654dd2aba155ab3eae55ea6a95737f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysqlcrypt-0.2.0-py3-none-any.whl:

Publisher: publish.yml on ivan-loh/pysqlcrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page