ezcrypt requires pycryptodomex to be installed. pip install pycryptodomex

import base64
import math
from Cryptodome.Cipher import AES
import hashlib

def encrypt(file, data, key):
key = bytes(key, 'utf-8')
data = bytes(data, 'utf-8')
md5_password = hashlib.md5(key).hexdigest()
md5_password = bytes(md5_password, 'utf-8')
cipher = cipherf(md5_password)
password_length = len(md5_password)
next_multiple_of_16 = 16 * math.ceil(password_length/16)
padded_password = data.rjust(next_multiple_of_16)
raw_ciphertext = cipher.encrypt(padded_password)
return base64.b64encode(raw_ciphertext).decode('utf-8')

def decrypt(file, data, key):
key = bytes(key, 'utf-8')
md5_password = hashlib.md5(key).hexdigest()
md5_password = bytes(md5_password, 'utf-8')
common_cipher = cipherf(md5_password)
raw_ciphertext = base64.b64decode(data)
decrypted_message_with_padding = common_cipher.decrypt(raw_ciphertext)
return decrypted_message_with_padding.decode('utf-8').strip()

def cipherf(md5_password):
IV = b'IVIVIVIVIVIVIVIV'
cipher = AES.new(md5_password, AES.MODE_CBC, IV)
return cipher

if __name__ == '__main__':
encrypt("test", "please", "work")
printr = decrypt("test", "work")
print(printr)