A pure Python implementation of crypt(3) from GNU libc
Project description
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.
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.
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)
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
Built Distribution
File details
Details for the file py-purecrypt-0.0.1.tar.gz
.
File metadata
- Download URL: py-purecrypt-0.0.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4775b809e8ce9b4132f40cd602d503ec18078b14901e36555763dc891cc5e7c |
|
MD5 | 2f5666e16759dde8872e9e1b7c7cab4d |
|
BLAKE2b-256 | d32afa3b9ef910ea347c63c3ccae6f9b7e7a74bafb95bacf94c6a9779feb0971 |
File details
Details for the file py_purecrypt-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: py_purecrypt-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e87296edd95892e6f9de8800e2c9e4c7b4ad24227cc07cf5a25611215336c02e |
|
MD5 | 6dd2e90c51e922da9352a33b58939bd0 |
|
BLAKE2b-256 | cf9e3492a7e73edefc2d6be54d90f2fc9e29cc1f51379ebb15f8dd63ad4f12bd |