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.