Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
920 views
in Technique[技术] by (71.8m points)

encryption - python - decrypt .csv file with openssl

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

question from:https://stackoverflow.com/questions/65950466/python-decrypt-csv-file-with-openssl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...