Skip to content

miniproto.crypto.mtproto.decrypt_payload

decrypt_payload(auth_key: bytes, msg_key: bytes, ciphertext: BytesLike, *, client_to_server: bool = False) -> bytes

Verify an MTProto message key and decrypt its AES-IGE payload.

Parameters:

  • auth_key (bytes) – Exactly 256 bytes of authorization-key material.
  • msg_key (bytes) – The 16-byte packet message key.
  • ciphertext (BytesLike) – Block-aligned AES-IGE ciphertext.
  • client_to_server (bool) – Defaults to false because received packets normally use the server-to-client derivation direction.

Returns:

  • bytes – The complete plaintext, including MTProto padding.

Raises:

  • ValueError – If lengths are invalid or the recomputed msg_key differs.

Message-key comparison occurs in the selected backend; this function does not parse the plaintext envelope or authenticate arbitrary transport data.