miniproto.crypto.mtproto.encrypt_payload
miniproto.crypto.mtproto.encrypt_payload
Section titled “miniproto.crypto.mtproto.encrypt_payload”encrypt_payload(auth_key: bytes, plaintext: BytesLike, *, client_to_server: bool = True, padding: bytes | None = None) -> EncryptedPayloadPad and AES-IGE-encrypt one MTProto payload.
Parameters:
- auth_key (
bytes) – Exactly 256 bytes of authorization-key material. - plaintext (
BytesLike) – Unpadded MTProto payload bytes. - client_to_server (
bool) – Uses the client-to-server derivation direction by default. - padding (
bytes | None) – Optional caller-provided random padding. If omitted, this wrapper obtains the minimum compliant length fromos.urandom.
Returns:
EncryptedPayload– The key identifier, message key, and encrypted payload components.
Raises:
ValueError– If key length, padding length (12 through 1024 bytes), or final AES block alignment is invalid.
The default only chooses a compliant padding length; callers who supply
padding are responsible for its unpredictability. Encryption backend
selection follows :mod:miniproto.crypto.native and does not change output
format.