Skip to main content

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

py-purecrypt-0.0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

py_purecrypt-0.0.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file py-purecrypt-0.0.2.tar.gz.

File metadata

  • Download URL: py-purecrypt-0.0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for py-purecrypt-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7eee941b6087bf7c44ac2279a28b6829d5ea09b28393dacbfd5c756e6dafa7a6
MD5 7d161d371aea4e006f8a6aefdbdc1fba
BLAKE2b-256 69beb7f18fda05a98f864dbcd234acd20b107d520001c72db5a3cd98dc0d0578

See more details on using hashes here.

File details

Details for the file py_purecrypt-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_purecrypt-0.0.2-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

Hashes for py_purecrypt-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd57205e7e315b31a6eb99aa935c46b7ce7b2572ee9d91bd331e256cd58c1b68
MD5 4dc2b924079e97f2cdbc93517d8f5a7d
BLAKE2b-256 f25a905302175645eae301d1cf4a229d63cf6090ec4a3beadb5ab8d27703ed28

See more details on using hashes here.

Supported by

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