daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from hashlib import md5
  2. from base64 import b64decode
  3. from base64 import b64encode
  4. from Crypto.Cipher import AES
  5.  
  6.  
  7. BLOCK_SIZE = 16  # Bytes
  8. SECRET_KEY = "T^aKDV#Kku7NJ*!p"
  9. iv = '\xdb\x68\xca\xd9\x12\xf7\x4f\x21\xa0\xbe\xb4\x15\x86\x46\xcd\x96'
  10.  
  11. def pad(s):
  12.     number_character_will_pad = BLOCK_SIZE - len(s) % BLOCK_SIZE
  13.     pad_character = chr(number_character_will_pad)
  14.     return s + number_character_will_pad * pad_character
  15.  
  16.  
  17. def unpad(s):
  18.     pad_character = s[len(s) - 1:]
  19.     number_pad_character = ord(pad_character)
  20.     return s[:-number_pad_character]
  21.  
  22.  
  23. class AESCipher:
  24.     def __init__(self):
  25.         self.key = SECRET_KEY
  26.  
  27.     def encrypt(self, raw):
  28.         raw = pad(raw)
  29.         cipher = AES.new(self.key, AES.MODE_CBC, iv)
  30.         return b64encode(cipher.encrypt(raw))
  31.  
  32.     def decrypt(self, enc):
  33.         enc = b64decode(enc)
  34.         cipher = AES.new(self.key, AES.MODE_CBC, iv)
  35.         return unpad(cipher.decrypt(enc))
  36.  
  37.  
  38. # 7b54ffb3965bd68acbcf77d765299c5153cc1823d907edb84983664061fea16f
RAW Paste Data
Top