Download an encrypted file from a url

0

I have this url, it's an encrypted image of whatsapp:

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

And this is the key to decrypting:

fhE5/WIJmz46IsnTeI0FpLrD7MneIWH7QWSUUvul0p4=

I'm 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)

When the run does not show any error, the file is created, but the image can not be opened.

    
asked by anonymous 06.09.2017 / 16:55

1 answer

0

I had to pass first to base64 to "refkey".

refkey = base64.b64decode(refkey)
    
08.09.2017 / 21:23