SHARE
TWEET

Untitled

a guest Jun 26th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import getpass
  3. from Crypto import Random
  4. from Crypto.Hash import SHA256
  5. from Crypto.Cipher import AES
  6.  
  7. def decrypt(s_enc, key_hash):
  8.     iv = s_enc[0:AES.block_size]
  9.     s_enc = s_enc[AES.block_size:]
  10.     cipher = AES.new(key_hash, AES.MODE_CBC, iv)
  11.     return cipher.decrypt(s_enc)
  12.  
  13. def encrypt(s, key_hash):
  14.     iv = Random.new().read(AES.block_size)
  15.     cipher = AES.new(key_hash, AES.MODE_CBC, iv)
  16.     extra = len(s) % 16
  17.     if extra > 0:
  18.         s = s + (b' ' * (16 - extra))
  19.     s_enc = iv + cipher.encrypt(s) # prepend IV
  20.     return s_enc
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top