def __decrypt_payload_chunks(self, payloadchunks):
decrypted_payload = ''
for chunk in payloadchunks:
payloadchunk = json.JSONDecoder().decode(chunk)
payload = payloadchunk.get('payload')
decoded_payload = base64.standard_b64decode(payload)
encryption_envelope = json.JSONDecoder().decode(decoded_payload)
# Decrypt the text
cipher = AES.new(
self.encryption_key,
AES.MODE_CBC,
base64.standard_b64decode(encryption_envelope['iv']))
ciphertext = encryption_envelope.get('ciphertext')
plaintext = cipher.decrypt(base64.standard_b64decode(ciphertext))
# unpad the plaintext
plaintext = json.JSONDecoder().decode(Padding.unpad(plaintext, 16))
data = plaintext.get('data')
# uncompress data if compressed
if plaintext.get('compressionalgo') == 'GZIP':
decoded_data = base64.standard_b64decode(data)
data = zlib.decompress(decoded_data, 16 + zlib.MAX_WBITS)
else:
data = base64.standard_b64decode(data)
decrypted_payload += data
decrypted_payload = json.JSONDecoder().decode(decrypted_payload)[1]['payload']['data']
decrypted_payload = base64.standard_b64decode(decrypted_payload)
return json.JSONDecoder().decode(decrypted_payload)
评论列表
文章目录