0

I'm receiving from a counterpart encrypted .csv files.

I can successfully decrypt those using open ssl and the following command:

openssl enc -d -aes-128-cbc -K my_key  –iv my_iv -in input_file.csv -out output_file.csv

I'm trying to do the same in python so that I can deploy that to my app (AWS Lambda) but I haven't found anything related to such a thing in SO, which really surprises me since this looks such a basic case to me.

I've found pycrypto, and other module but nothing seems to concern my case.

Would you have any idea ?

Thanks

yeye
  • 503
  • 4
  • 19
  • 2
    Does this answer your question? [AES-128 CBC decryption in Python](https://stackoverflow.com/questions/46904355/aes-128-cbc-decryption-in-python) – Olvin Roght Jan 29 '21 at 07:47

1 Answers1

0

Thanks to Olvin Roght, I digged deeper into the topic and found the solution for my case:

from Crypto.Cipher import AES
import Crypto.Cipher.AES
from binascii import hexlify, unhexlify
key = unhexlify(my_key)
IV = unhexlify(my_iv)
decipher = AES.new(key, AES.MODE_CBC, IV)
ciphertext = open(in_filename, "rb").read()
plaintext = decipher.decrypt(ciphertext)
f = open(out_filename, 'wb')
binary_format = bytes(plaintext)
f.write(binary_format)
f.close()
yeye
  • 503
  • 4
  • 19