I wanted to know if I can decrypt this image that uses AES ECBand CBC In PYTHON.
Question:
I wanted to know if I can decrypt this image that uses AES ECBand CBC In PYTHON. The ECB Method is used in below code, but i wanta decryption method for cbc also. Please make sure the sameencryption is used. please provide a working code for thedecryption part. Code used for encryption is (Code done in visualstudios)
filename = "image.jpg"
filename_out = "EncryptedAES"
key = "aaaabbbbccccdddd"
def pad(data):
return data + b"x00"*(16-len(data)%16)
def convertRGB(data):
r, g, b = tuple(map(lambda d: [data[i] for i inrange(0,len(data)) if i%3==d], [0,1,2]))
pixels = tuple(zip(r,g,b))
return pixels
def process_image(filename):
im = Image.open(filename)
data = im.convert("RGB").tobytes()
original = len(data)
new = convertRGB(aes_ecb_encrypt(key, pad(data))[:original])
im2 = Image.new(im.mode, im.size)
im2.putdata(new)
im2.save(filename_out+"."+"png", "png")
def aes_ecb_encrypt(key, data, mode=AES.MODE_ECB):
IV = "A"*16
aes = AES.new(key.encode('utf-8'), mode)
new_data = aes.encrypt(data)
return new_data
process_image(filename)
When I put the command process_image('imagefilename.jpg'), i getan encrypted form of image with AES. I need the decryption processfor this method. This code directly works to produce an AESencrypted output