forked from xxNull-lsk/video_downloder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaes128.py
More file actions
30 lines (22 loc) · 647 Bytes
/
Copy pathaes128.py
File metadata and controls
30 lines (22 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: UTF-8 -*-
from Crypto.Cipher import AES
import hashlib
def md5(data):
m = hashlib.md5()
m.update(data)
return m.hexdigest()
class Aes128:
iv = b'\0' * 16
key = None
def __init__(self, key):
self.key = key
def decrypt(self, data):
cryptor = AES.new(self.key, AES.MODE_CBC, self.iv)
return cryptor.decrypt(data)
@staticmethod
def pad(s):
bs = AES.block_size
return s + (bs - len(s) % bs) * chr(bs - len(s) % bs)
def encrypt(self, data):
cryptor = AES.new(self.key, AES.MODE_CBC, self.iv)
return cryptor.encrypt(self.pad(data))