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
authenticatorparameter embeds additional context data for verification - Decryption auto-detects the version from the ciphertext header
License
MIT
🍌
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aa211fbabdd6fc92c20f3aa8ee43b2388692ba58c9296913a96528393c1e505
|
|
| MD5 |
dde31e724a8b96c72d659ebebd4780ab
|
|
| BLAKE2b-256 |
13f24a9130b7fc19aca933b19cf20ea9f781b8769a9e0e13274440ba9f9de1d4
|
Provenance
The following attestation bundles were made for pysqlcrypt-0.2.0.tar.gz:
Publisher:
publish.yml on ivan-loh/pysqlcrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysqlcrypt-0.2.0.tar.gz -
Subject digest:
9aa211fbabdd6fc92c20f3aa8ee43b2388692ba58c9296913a96528393c1e505 - Sigstore transparency entry: 780738768
- Sigstore integration time:
-
Permalink:
ivan-loh/pysqlcrypt@9299909286472a6468dd3343ec584393318c13f0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ivan-loh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9299909286472a6468dd3343ec584393318c13f0 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e34ccd4b8cbc378c94211afbe9518b7e2fa5ce7541580b12161d44efd3a12b26
|
|
| MD5 |
ae346df099afa241e8ed64d01ad70ad2
|
|
| BLAKE2b-256 |
b1594065017a8a4c50304cf31500aa555654dd2aba155ab3eae55ea6a95737f8
|
Provenance
The following attestation bundles were made for pysqlcrypt-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on ivan-loh/pysqlcrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysqlcrypt-0.2.0-py3-none-any.whl -
Subject digest:
e34ccd4b8cbc378c94211afbe9518b7e2fa5ce7541580b12161d44efd3a12b26 - Sigstore transparency entry: 780738769
- Sigstore integration time:
-
Permalink:
ivan-loh/pysqlcrypt@9299909286472a6468dd3343ec584393318c13f0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ivan-loh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9299909286472a6468dd3343ec584393318c13f0 -
Trigger Event:
release
-
Statement type: