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

Uploaded Source

Built Distribution

py_purecrypt-0.0.3-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py-purecrypt-0.0.3.tar.gz
Algorithm Hash digest
SHA256 eafc552a27489682c9dc5c3c6f18b2b046a38ac1cbbba5a82353af392f7eadca
MD5 31c560bfabf0807ec30d5087f88b3e14
BLAKE2b-256 083b06e187ea9e6cca65c06d34f8eb953fbc8934b260aed061928d704f019844

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_purecrypt-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for py_purecrypt-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1545c1a23916c14f10c58fc2f3911ba07fe1124557a6136e5cf97ee33bdba986
MD5 548341b6113d68b028956d12ac964577
BLAKE2b-256 ef5b5bdfca7d8cffdfe06314271c72b6a88c02eda8711150f06fa41c2559ae54

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