0

I have a video file which I am trying decrypt . The key is stored in a file. For some reasons it's not working and giving me this error "TypeError: Object type <class 'str'> cannot be passed to C code"

DecryptFile function I wrote takes 3 parameters

  • input file name ("input.ts")
  • output file name ("output.ts")
  • key for decryption ("k.kjs").

What I want it to do is decrypt the file with the key provided and save it with output name I gave . I am using Python 3.7.1

from Crypto.Cipher import AES
import os

def DecryptFile(infile,outfile,keyfile):
    data = open(infile,"rb").read()
    key = open(keyfile,"rb").read()
    print(type(data))
    iv = '\x00'*15 + chr(1)
    aes_crypter = AES.new(key,  AES.MODE_CBC,  iv)
    a = aes_crypter.decrypt(data)
    with open(outfile, 'wb') as out_file:
        out_file.write(a)



DecryptFile("input.ts","output.ts","k.kjs")
CristiFati
  • 38,250
  • 9
  • 50
  • 87

1 Answers1

0

According to [ReadTheDocs.PyCryptodome]: AES - Crypto.Cipher.AES.new(key, mode, *args, **kwargs), iv should be:

  • Of type bytes
  • A kwarg

To get past this error, modify 2 lines of your code:

# ...
iv = b'\x00' * 15 + b'\x01'
aes_crypter = AES.new(key, AES.MODE_CBC, iv=iv)
# ...
CristiFati
  • 38,250
  • 9
  • 50
  • 87