从网址下载加密文件

时间:2017-09-06 19:25:22

标签: python cryptography whatsapp

我有这个网址,它是whatsapp的加密图片:

fhE5/WIJmz46IsnTeI0FpLrD7MneIWH7QWSUUvul0p4=

这是解密的关键:

#!/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)

我正在尝试使用以下代码解密此网址:

date +"%T"

如果运行没有显示任何错误,则会创建文件,但无法打开图像。

1 个答案:

答案 0 :(得分:1)

我必须先将base64传递给" refkey"。

refkey = base64.b64decode (refkey)