Docsity

Python Script for Encrypting and Decrypting Files using pyAesCrypt - Prof. Lab, Lab Reports of Security Analysis

Toggle sidebar
bg1
Encrypt and Decrypt file
Code
Encrypt:
import pyAesCrypt
import sys
import os
# Choose the target directory
target_dir = "D:\\temp\\"
print(target_dir)
# custom encyption/decryption buffer size (default is 64KB)
bufferSize = 128 * 1024
# Input the password for encryption
password = input("Please input the p: ")
# Select every files in target dir
for path, subdirs, files in os.walk(target_dir):
for name in files:
origin_path = os.path.join(path, name)
encrypted_path = os.path.join(path, name+".aes")
try:
# Encypte the file
pyAesCrypt.encryptFile(origin_path, encrypted_path, password,
bufferSize)
# remove the original files
os.remove(origin_path)
except Exception as e:
print(e)
pf3

Partial preview of the text

Download Python Script for Encrypting and Decrypting Files using pyAesCrypt - Prof. Lab and more Lab Reports Security Analysis in PDF only on Docsity!

Encrypt and Decrypt file Code Encrypt: import pyAesCrypt import sys import os

Choose the target directory

target_dir = "D:\temp\" print(target_dir)

custom encyption/decryption buffer size (default is 64KB)

bufferSize = 128 * 1024

Input the password for encryption

password = input("Please input the p: ")

Select every files in target dir

for path, subdirs, files in os.walk(target_dir): for name in files: origin_path = os.path.join(path, name) encrypted_path = os.path.join(path, name+".aes") try:

Encypte the file

pyAesCrypt.encryptFile(origin_path, encrypted_path, password, bufferSize)

remove the original files

os.remove(origin_path) except Exception as e: print(e)

Decrypt: import pyAesCrypt import sys import os

Choose the target directory

target_dir = "D:\temp\" print(target_dir)

custom encyption/decryption buffer size (default is 64KB)

bufferSize = 128 * 1024

Input the password for encryption

password = input("Please input the p: ")

Select every files in target dir

for path, subdirs, files in os.walk(target_dir): for name in files: origin_path = os.path.join(path, name) decrypted_path = os.path.join(path, name.strip(".aes")) try:

Encypte the file

pyAesCrypt.decryptFile(origin_path, decrypted_path, password, bufferSize)

remove the original files

os.remove(origin_path) except Exception as b: print(b) Result: File encrypted: