cryptease provides an simple API and command line tool for encrypting and decrypting files and other blobs of data. cryptease is able to encrypt and decrypt content in chunks, which can be useful for encrypting and decrypting extremely large files. It also supports opening encrypted files as a file-like-object for reading decrypted content on the fly.
Cryptease works with Python versions 2 and 3.
The easiest way to install cryptease
is with pip
pip install cryptease
There is a simple command line utility shipped with this library that can be used to quickly encrypt a file
$ crypt.py --encrypt file.txt --output-file file.enc
and decrypt a file
$ crypt.py --decrypt file.enc --output-file file.dec
The cryptease
library provides an way to build custom software and applications
that need to encrypt or decrypt files in one shot or one chunk at a time. Use
cryptease.encrypt
to encrypt a string in memory using AES-256 encryption
import io
import cryptease as crypt
content = 'Hello, World!'
key = crypt.kdf('password')
ciphertext = b''
for chunk in crypt.encrypt(content, key):
ciphertext += chunk
for chunk in crypt.decrypt(io.BytesIO(ciphertext), key):
print chunk,
To serialize the encrpyted data (i.e., cipher text) and some metadata about the
key to a flat file, simply pass the filename
argument
import io
import cryptease as crypt
content = 'Hello, World!'
key = crypt.kdf('password')
crypt.encrypt(io.BytesIO(content), key, filename='file.enc')
To deserialize the encrypted file to a decrypted file, simply open
the file,
pass it to cryptease.encrypt
, and pass the filename
parameter to
cryptease.decrypt
import cryptease as crypt
with open('file.enc') as fp:
key = crypt.key_from_file(fp, 'password')
crypt.decrypt(fp, key, filename='file.dec')