Skip to main content

A pure Python implementation of common UNIX password encryption

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.

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.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-purecrypt-0.0.0.tar.gz
  • Upload date:
  • Size: 8.5 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.0.tar.gz
Algorithm Hash digest
SHA256 b960ff4942324bea4d2c2cc1ad5e7da6098767b231519557d5e82fcad8a58ba8
MD5 3c07e34aff592dc4e78b3cdb8d01d638
BLAKE2b-256 cea3ead662714cdb6ef4c40b2d55c5e6b131afe739a2d8717223963b5693a9a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_purecrypt-0.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18a3e5198f6633fb8362c1d5a44d84d98779bad7fcb4ed33d0ca51518fc61579
MD5 d10fe673e80b02438dbda12c7e2db1f1
BLAKE2b-256 43e29bd16ae50d89f49959ad2187676c9303ca213ee6ac66fce76edcd5f9bf1f

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