Advertisement
smatskevich

AES

Sep 26th, 2022
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import hashlib
  2. from Crypto import Random
  3. from Crypto.Cipher import AES
  4. from Crypto.Util import Padding
  5.  
  6.  
  7. progLibMD5 = hashlib.md5("ProgLib".encode('utf-8'))
  8. print(progLibMD5.hexdigest())
  9.  
  10. key = progLibMD5.digest()
  11.  
  12. data = "Мама мыла раму"
  13.  
  14. initial_vector = Random.new().read(AES.block_size)
  15. cipher = AES.new(key, AES.MODE_CBC, initial_vector)
  16. padding = Padding.pad(data.encode(), AES.block_size)
  17. encrypted = cipher.encrypt(padding)
  18.  
  19. print(encrypted)
  20.  
  21. cipher2 = AES.new(key, AES.MODE_CBC, initial_vector)
  22. padded = cipher2.decrypt(encrypted)
  23. decrypted = Padding.unpad(padded, AES.block_size)
  24.  
  25. print(decrypted.decode())
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement