Encrypt large files without loading the entire file into memory.
Project description
Buffered Encryption
Encrypt large data files chunk-by-chunk, securely.
This package uses AES in GCM mode to encrypt and decrypt file streams.
It relies on the cryptography library to perform the encryption.
big unencrypted file, verification data --> encrypt and sign --> encrypted file, iv, tag
big unencrypted file <-- decrypt and verify <-- encrypted file, iv, tag, verification data
Example
import os
from buffered_encryption import EncryptionIterator, DecryptionIterator
plaintext = open("plain.txt","rb")
key = os.urandom(32)
sig = os.urandom(12)
enc = EncryptionIterator(plaintext,key,sig)
with open("cipher","wb") as ciphertext:
for chunk in enc:
ciphertext.write(chunk)
plaintext.close()
ciphertext = open("cipher","rb")
dec = DecryptionIterator(ciphertext,key,sig,enc.iv,enc.tag)
with open("plain.dec.txt","wb") as decrypted:
for chunk in dec:
decrypted.write(chunk)
ciphertext.close()
Classes
class EncryptionIterator:
"""
Encrypt a file iteratively
Parameters
----------
file : io.BytesIO
The file buffer to encrypt
key : bytes
The secret key for AES encryption
signature : bytes
Additional data used to verify the key later
chunk_size : int
How much data to encrypt per iteration
Attributes
----------
iv : bytes
The 12-byte initialization vector for GCM. You will need this value for decryption.
tag : bytes
The tag to verfiy data integrity on decryption
"""
class DecryptionIterator:
"""
Decrypt a file iteratively
Parameters
----------
ciphertext : io.BytesIO
The file buffer to decrypt
key : bytes
The secret key for AES decryption
signature : bytes
Additional data used to verify the key
iv : bytes
The initialization vector from the EncryptionIterator object
tag : bytes
The tag used for data integrity from the EncryptionIterator object
chunk_size : int
How much data to decrypt per iteration
"""
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
Built Distribution
Close
Hashes for buffered_encryption-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 674193559d1af384607afba897d7a8053c941f6396a52da74930c58a469d1dc9 |
|
MD5 | b6fd640415ef3913af85eec4d5861aa3 |
|
BLAKE2b-256 | 38786bfb7a6ac24585b10e020cb3e184f04ecaaf74397a7b75d6d2cf1743ec2e |
Close
Hashes for buffered_encryption-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c16ecaf2fdd31e1d698d6a548a7b886bf748f321f398489c3fb3fc4d81bcb31 |
|
MD5 | 337be6a19b248179f793dbe201a4e103 |
|
BLAKE2b-256 | 630fd83b69cd63aeb539c57bcc5423a07b1a067ca3627ab6e78eb7720d007abf |