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.

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)

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

Uploaded Source

Built Distribution

py_purecrypt-0.1.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-purecrypt-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.1.tar.gz
Algorithm Hash digest
SHA256 01eef2289525f584a6320ffb3a984331eea02c6cb4ca381dee8279685b1243b1
MD5 257985300f5df26bbcad136125e61484
BLAKE2b-256 2e670a353005d1f29cdc64e20cef72237c9704cd0d2eb51178feac132ae23f95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_purecrypt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1343ea0ede5dae70356f6752a4d277080bc5cddbe4be83f318aa94e05e696697
MD5 dcf16f35c4ff326a2c1e4f3baf24c426
BLAKE2b-256 0aa9165463e7ab3bb6d0108f89f0322a6d099e44245248e0e0ff61ce43b2fc31

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