Download an encrypted file from a url

Asked

Viewed 384 times

0

I have this URL, it’s an encrypted Whatsapp image:

https://mmg-fna.whatsapp.net/d/f/Agli1Cej_5hAtjpKhGZ3xl2TKU9dWRXcOE_k0KLvJOWZ.enc

And this is the key to decrypting:

fhE5/WIJmz46IsnTeI0FpLrD7MneIWH7QWSUUvul0p4=

I am trying to decrypt this url using the following code:

#!/usr/bin/env python2
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen
from axolotl.kdf.hkdfv3 import HKDFv3
from axolotl.util.byteutil import ByteUtil
import binascii
from Crypto.Cipher import AES
from pprint import pprint 

class Decrypter():

    __arrayDeBytes = None

    def decrypt(self, url, mediaKey):

        encimg = urlopen(url).read()
        cryptKeys  = '576861747341707020496d616765204b657973'

        derivative = HKDFv3().deriveSecrets(mediaKey, binascii.unhexlify(cryptKeys), 112)
        parts = ByteUtil.split(derivative, 16, 32)
        iv = parts[0]
        cipherKey = parts[1]
        e_img = encimg[:-10]
        AES.key_size=128
        cr_obj = AES.new(key=cipherKey,mode=AES.MODE_CBC,IV=iv)
        self.__arrayDeBytes = bytearray(cr_obj.decrypt(e_img))

    def salvar(self, caminho):
        with open(caminho, 'wb') as f:
            f.write(self.__arrayDeBytes)

While running shows no error, the file is created but cannot open the image.

1 answer

0


I had to go first to Base64 to "refkey".

refkey = base64.b64decode(refkey)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.