January 2019
Beginner
318 pages
8h 23m
English
In this section, we will learn about the pyAesCrypt module of Python. pyAesCrypt is a file encryption module that uses AES256-CBC to encrypt/decrypt files and binary streams.
Install pyAesCrypt as follows:
pip3 install pyAesCrypt
Create a script called file_encrypt.py and write the following code in it:
import pyAesCryptfrom os import stat, remove# encryption/decryption buffer size - 64KbufferSize = 64 * 1024password = "#Training"with open("sample.txt", "rb") as fIn: with open("sample.txt.aes", "wb") as fOut: pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)# get encrypted file sizeencFileSize = stat("sample.txt.aes").st_size
Run the script as follows:
student@ubuntu:~/work$ python3 file_encrypt.py ...
Read now
Unlock full access