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
plaintext = decrypt_by_passphrase("passphrase", ciphertext, encoding="utf-8")

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).

Version Reference

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

Notes

  • For NVARCHAR compatibility, use encoding="utf-16-le"
  • 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.1.0.tar.gz (4.1 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.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysqlcrypt-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pysqlcrypt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68553da3ccd9ac8b15bab35e6a0ccab34a2bc3a3cf54b70d360f115cbc377f7a
MD5 91330ffc9d03a5b9e140b729018a8105
BLAKE2b-256 79cf2131cf228a906dd1c76ab61eee093bf83b12ff74db5730c7c33da354715e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysqlcrypt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pysqlcrypt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e606fdbdcf79107a627b7e1ae25049ff235f6d1b3d60453cedee09763fc9a4d3
MD5 d7aa4fe1786188afc531c5050a50a348
BLAKE2b-256 451f389e87a0c82df7060235a72aa6ce99b12444de6048cbfdfd87c6950356fe

See more details on using hashes here.

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