I just found pycrypto today, and I've been working on my AES encryption class. Unfortunately it only half-works. self.h.md5 outputs md5 hash in hex format, and is 32byte. This is the output. It seems to decrypt the message, but it puts random characters after decryption, in this case \n\n\n... I think I have a problem with block size of self.data, anyone know how to fix this?
Jans-MacBook-Pro:test2 jan$ ../../bin/python3 data.py b'RLfGmn5jf5WTJphnmW0hXG7IaIYcCRpjaTTqwXR6yiJCUytnDib+GQYlFORm+jIctest 1 2 3 4 5 endtest\n\n\n\n\n\n\n\n\n\n'
from Crypto.Cipher import AES from base64 import b64encode, b64decode from os import urandom class Encryption(): def __init__(self): self.h = Hash() def values(self, data, key): self.data = data self.key = key self.mode = AES.MODE_CBC self.iv = urandom(16) if not self.key: self.key = Cfg_Encrypt_Key self.key = self.h.md5(self.key, True) def encrypt(self, data, key): self.values(data, key) return b64encode(self.iv + AES.new(self.key, self.mode, self.iv).encrypt(self.data)) def decrypt(self, data, key): self.values(data, key) self.iv = b64decode(self.data)[:16] return AES.new(self.key, self.mode, self.iv).decrypt(b64decode(self.data)[16:])