Skip to main content

pyAesCrypt

https://travis-ci.org/marcobellaccini/pyAesCrypt.svg?branch=master https://pepy.tech/badge/pyaescrypt

About pyAesCrypt

pyAesCrypt is a Python 3 file-encryption module and script that uses AES256-CBC to encrypt/decrypt files and binary streams.

pyAesCrypt is compatible with the AES Crypt file format (version 2).

It is Free Software, released under the Apache License, Version 2.0.

pyAesCrypt is brought to you by Marco Bellaccini - marco.bellaccini(at!)gmail.com.

IMPORTANT SECURITY NOTE: version 2 of the AES Crypt file format does not authenticate the “file size modulo 16” byte. This implies that an attacker with write access to the encrypted file may alter the corresponding plaintext file size by up to 15 bytes.

NOTE: there is no low-level memory management in Python, hence it is not possible to wipe memory areas were sensitive information was stored.

Module usage example

Here is an example showing encryption and decryption of a file:

import pyAesCrypt
# encryption/decryption buffer size - 64K
bufferSize = 64 * 1024
password = "foopassword"
# encrypt
pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password, bufferSize)
# decrypt
pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password, bufferSize)

by calling the stream-oriented functions, you can work with binary streams too:

import pyAesCrypt
from os import stat, remove
# encryption/decryption buffer size - 64K
bufferSize = 64 * 1024
password = "foopassword"

# encrypt
with open("data.txt", "rb") as fIn:
    with open("data.txt.aes", "wb") as fOut:
        pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)

# get encrypted file size
encFileSize = stat("data.txt.aes").st_size

# decrypt
with open("data.txt.aes", "rb") as fIn:
    with open("dataout.txt", "wb") as fOut:
        try:
            # decrypt file stream
            pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize, encFileSize)
        except ValueError:
            # remove output file on error
            remove("dataout.txt")

you can also perform in-memory encryption/decryption (using BytesIO):

import pyAesCrypt
import io

bufferSize = 64 * 1024
password = "foopassword"

# binary data to be encrypted
pbdata = b"This is binary plaintext \x00\x01"

# input plaintext binary stream
fIn = io.BytesIO(pbdata)

# initialize ciphertext binary stream
fCiph = io.BytesIO()

# initialize decrypted binary stream
fDec = io.BytesIO()

# encrypt stream
pyAesCrypt.encryptStream(fIn, fCiph, password, bufferSize)

# print encrypted data
print("This is the ciphertext:\n" + str(fCiph.getvalue()))

# get ciphertext length
ctlen = len(fCiph.getvalue())

# go back to the start of the ciphertext stream
fCiph.seek(0)

# decrypt stream
pyAesCrypt.decryptStream(fCiph, fDec, password, bufferSize, ctlen)

# print decrypted data
print("Decrypted data:\n" + str(fDec.getvalue()))

Script usage examples

Encrypt file test.txt in test.txt.aes:

pyAesCrypt -e test.txt

Decrypt file test.txt.aes in test.txt:

pyAesCrypt -d test.txt.aes

Encrypt file test.txt in test2.txt.aes:

pyAesCrypt -e test.txt -o test2.txt.aes

Decrypt file test.txt.aes in test2.txt:

pyAesCrypt -d test.txt.aes -o test2.txt

Metadata

Release files for pyAesCrypt 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyAesCrypt 0.4.1
File Size Uploaded Provenance Actions
pyAesCrypt-0.4.1.tar.gz 13.4 kB Without provenance Details for pyAesCrypt-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyAesCrypt 0.4.1
File Interpreter ABI Platform Actions
pyAesCrypt-0.4.1-py3-none-any.whl Python 3 none any Details for pyAesCrypt-0.4.1-py3-none-any.whl

Total release size: 26.6 kB

Release files / pyAesCrypt-0.4.1.tar.gz

Download URL pyAesCrypt-0.4.1.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0a7c0c3abde677ce3b89111b38e9891c624d17fc9b651f01da8507737420ebfb
BLAKE2b-256 checksum
How to use checksums
6c7a9ec644cae79146f44f1e918c885fdf92b28e7d6710d79ced09ccf3435047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.8.1 pkginfo/1.2.1 requests/2.12.4 setuptools/33.1.1 requests-toolbelt/0.7.0 clint/0.5.1 CPython/3.5.3 Linux/4.9.0-8-amd64

Release files / pyAesCrypt-0.4.1-py3-none-any.whl

Download URL pyAesCrypt-0.4.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
840f35d67d1456b9b4c35ac5b33a276ba72072d880e7ed025de8cdeeb677cbc7
BLAKE2b-256 checksum
How to use checksums
cd61f0d6092275520427bee9a087834f16b7281891ee5d3e111fabf1eb0bf7d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.8.1 pkginfo/1.2.1 requests/2.12.4 setuptools/33.1.1 requests-toolbelt/0.7.0 clint/0.5.1 CPython/3.5.3 Linux/4.9.0-8-amd64

Security for pyAesCrypt 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page