Guest User

Раб пытается съесть свои глаза

a guest
Aug 3rd, 2019
1,982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from Crypto.PublicKey import RSA
  2. from Crypto.Random import get_random_bytes
  3. from Crypto.Cipher import AES, PKCS1_OAEP
  4. import os, sys
  5.  
  6. def decrypt(file):
  7.  
  8.     file_in = open(file, "rb")
  9.     file_out = open(str(file[:-4]), "wb")
  10.     private_key = RSA.import_key(open("private.pem").read())
  11.  
  12.     enc_session_key, nonce, tag, ciphertext = \
  13.        [ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
  14.  
  15.     cipher_rsa = PKCS1_OAEP.new(private_key)
  16.     session_key = cipher_rsa.decrypt(enc_session_key)
  17.  
  18.     cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
  19.     data = cipher_aes.decrypt_and_verify(ciphertext, tag)
  20.     file_out.write(data)
  21.     print(file + " РАСШИФРОВАН!")
  22.     os.remove(file)
  23.  
  24. def walk(dir):
  25.     for name in os.listdir(dir):
  26.         path = os.path.join(dir, name)
  27.         if os.path.isfile(path): decrypt(path)
  28.         else: walk(path)
  29. #Тут фигачь ту деректорию где прячеш файлы
  30. walk("/home/q/Шаблоны/1")
  31. print("---------------------------------------------------------------" )
Advertisement
Add Comment
Please, Sign In to add comment