py-purecrypt
A pure Python implementation of the crypt(3) function provided in the GNU C library (glibc). This implementation supports the MD5, SHA256, and SHA512 variants.
This package provides a drop-in replacement for the deprecated (and soon to
be removed) crypt package provided in the Python standard library.
Because this is written in pure Python and depends only on the cryptography package, it should run on any platform supported by Python.
This implementation is not fast. If you're looking for speed, I suggest you consider alternatives such as bcrypt.
Installation
Install py-purecrypt from PyPI
using pip or your preferred Python package manager.
Usage
This section shows basic usage examples.
Using the Compatibility API
You can use this package as a drop-in replacement for the deprecated crypt
package that will soon be removed from the Python standard library. At present
this package supports only the MD5, SHA256, and SHA512 methods.
Example
import purecrypt as crypt
plaintext_pw = "Hello world!"
salt = crypt.mksalt(crypt.METHOD_SHA256, rounds=10000)
hashed_pw = crypt.crypt(plaintext_pw, salt)
Using the Native API
Encrypt a password
Choose a method and generate a salt, then encrypt.
from purecrypt import Crypt, Method
plaintext_password = "super secret"
salt = Crypt.generate_salt(Method.SHA512)
ciphertext_password = Crypt.encrypt(plaintext_password, salt)
When generating a salt you can specify the number of rounds to perform while encrypting.
from purecrypt import Crypt, Method
plaintext_password = "super secret"
salt = Crypt.generate_salt(Method.SHA256, rounds=10000)
ciphertext_password = Crypt.encrypt(plaintext_password, salt)
Validate a password
To validate a given password, you just need the ciphertext that was produced when the original password was encrypted.
from purecrypt import Crypt
# as produced by the previous example
ciphertext_password = "$5$rounds=10000$vGuBkkhnTmd9BHeFpw4vxHNHJ1bxFRZX$2xiip3lO0cjGg3tZMdled9LpChHk1nmpF6hU6ZW05W1"
plaintext_password = "super secret"
assert Crypt.is_valid(plaintext_password, ciphertext_password)
Metadata
Release files for py-purecrypt 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py-purecrypt-0.1.1.tar.gz | 8.2 kB | Without provenance | Details for py-purecrypt-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_purecrypt-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for py_purecrypt-0.1.1-py3-none-any.whl |
Total release size: 19.8 kB
Release files / py-purecrypt-0.1.1.tar.gz
| Download URL | py-purecrypt-0.1.1.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01eef2289525f584a6320ffb3a984331eea02c6cb4ca381dee8279685b1243b1
|
|
BLAKE2b-256 checksum How to use checksums |
2e670a353005d1f29cdc64e20cef72237c9704cd0d2eb51178feac132ae23f95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / py_purecrypt-0.1.1-py3-none-any.whl
| Download URL | py_purecrypt-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1343ea0ede5dae70356f6752a4d277080bc5cddbe4be83f318aa94e05e696697
|
|
BLAKE2b-256 checksum How to use checksums |
0aa9165463e7ab3bb6d0108f89f0322a6d099e44245248e0e0ff61ce43b2fc31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for py-purecrypt 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.