Beispiel #1
0
    def encryptImg(self,img, refkey, mimetype):
        print(mimetype)
        if(mimetype == "audio/wav"):
            derivative = HKDFv3().deriveSecrets(binascii.unhexlify(refkey),
                                            "WhatsApp Audio Keys", 112)
        else:
            derivative = HKDFv3().deriveSecrets(binascii.unhexlify(refkey),
                                            "WhatsApp Image Keys".encode(), 112)
        parts = ByteUtil.split(derivative, 16, 32)
        iv = parts[0]
        cipherKey = parts[1]
        macKey=derivative[48:80]
			
        mac = hmac.new(macKey,digestmod=hashlib.sha256)
        mac.update(iv)
	
        cipher = AES.new(key=cipherKey, mode=AES.MODE_CBC, IV=iv)
        imgEnc = cipher.encrypt(self.pad(img))

        mac.update(imgEnc)
        hash = mac.digest()
        hashKey = ByteUtil.trim(mac.digest(), 10)
	
        finalEnc =  imgEnc + hashKey

        return finalEnc
    def encryptImg(self, img, refkey):
        derivative = HKDFv3().deriveSecrets(binascii.unhexlify(refkey),
                                            binascii.unhexlify(WHATSAPP_KEY),
                                            112)
        parts = ByteUtil.split(derivative, 16, 32)
        iv = parts[0]
        cipherKey = parts[1]
        macKey = derivative[48:80]

        mac = hmac.new(macKey, digestmod=hashlib.sha256)
        mac.update(iv)

        cipher = AES.new(key=cipherKey, mode=AES.MODE_CBC, IV=iv)
        imgEnc = cipher.encrypt(self.pad(img))

        mac.update(imgEnc)
        hash = mac.digest()
        hashKey = ByteUtil.trim(mac.digest(), 10)

        finalEnc = imgEnc + hashKey
        return finalEnc