Skip to main content

Randomized Encryption Library

Project description

The randenc package provides simple symmetric message encryption and decryption functions with message packing, compression, cryptographic hashes, and automatically rotated random keys. It is designed for short messages such as user ID tokens and browser cookies. Usage example:

>>> from randenc import RandomEncryption
>>> import tempfile
>>> enc = RandomEncryption(tempfile.mkdtemp())
>>> code = enc.encrypt({u'message': u'Hello, world!'})
>>> len(code)
107
>>> enc.decrypt(code)
{u'message': u'Hello, world!'}

The encryption key and signing key are produced automatically (using os.urandom) and stored in the key directory. Each key will be deleted after one hour by default, invalidating all encrypted codes associated with that key.

The encrypt function packs the content using msgpack, compresses it using zlib (unless the compressed version is larger than than the uncompressed version), encrypts it using AES-128 (since AES-128 seems to be considered more secure than AES-256), signs it using HMAC over SHA-256, and encodes in URL-safe base 64 format. The decrypt function reverses that operation. If the code fails validation or has expired, the decrypt function raises DecryptionError.

This package is designed to be compatible with clusters. The keys may be stored on a shared volume using NFS or a FUSE-based filesystem. With a little work, the keys could be stored in a key-value store such as MongoDB.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

randenc-0.1.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file randenc-0.1.tar.gz.

File metadata

  • Download URL: randenc-0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randenc-0.1.tar.gz
Algorithm Hash digest
SHA256 ed55e9af58a14dad5e937d36e0da639a3b0757f1d8c628677c673edce43ceab8
MD5 b22bd15e31da8616193ba91a6abd277e
BLAKE2b-256 a817b8f02784826777280ea8a6aa66a52a4afdc47d0152c38802101173fbeca2

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