WhatsApp media encryption and decryption helpers.
This follows the same media-key expansion used by popular WhatsApp Web
clients: HKDF-SHA256 expands the 32-byte media key into IV, cipher, MAC, and
reference keys. The payload is then encrypted with AES-256-CBC and protected
with the first 10 bytes of an HMAC-SHA256 digest over IV || ciphertext.
Summary
Functions
Decrypts an encrypted media body, or accepts a server-declared unencrypted body when no encrypted SHA-256 is present, and validates all available integrity checks.
Derives WhatsApp media keys for the given media type.
Encrypts plaintext media bytes and returns upload metadata plus encrypted body.
Returns the WhatsApp HKDF context string for a media type.
Types
Functions
@spec decrypt_download(binary(), ExWapp.Media.Ref.t()) :: {:ok, binary()} | {:error, term()}
Decrypts an encrypted media body, or accepts a server-declared unencrypted body when no encrypted SHA-256 is present, and validates all available integrity checks.
@spec derive_keys(binary(), ExWapp.Media.media_type()) :: media_keys()
Derives WhatsApp media keys for the given media type.
@spec encrypt_upload(binary(), ExWapp.Media.media_type()) :: {:ok, ExWapp.Media.Upload.t(), binary()}
Encrypts plaintext media bytes and returns upload metadata plus encrypted body.
@spec media_info(ExWapp.Media.media_type()) :: binary()
Returns the WhatsApp HKDF context string for a media type.