Read the playlist’s encryption method first
For HLS METHOD=AES-128, the key tag describes the key used for the following segments until another key tag changes it. The HLS key-tag specification defines this state. Keep the active key and IV rule while walking the playlist in order.
HLS AES-128 with the identity key format is distinct from EME Clear Key and from SAMPLE-AES. Use the method and key format in the actual playlist. Calling every readable key URL “Clear Key” hides differences that matter when building the client.
Recover the requests around the playlist
The app can obtain a playlist URL through a playback-start call. Key and media requests can use different hosts, cookies or tokens. Resolve relative URLs against the playlist URL and preserve the headers the app supplies for each host.
Record redirect behavior and token refresh too. A segment that works directly after login does not establish that the same captured URL will work tomorrow. The ExoPlayer network flow shows how to separate entitlement, playlist, key and media traffic.
Choose the IV for each segment
An explicit IV in the key tag supplies the AES-CBC initialization vector. For an AES-128 media segment without that IV, use the media sequence number as a 128-bit, big-endian value. Initialization sections have their own requirements; do not apply a media-segment shortcut to every object.
sequence 7, no explicit IV:
00000000000000000000000000000007
explicit IV ending in 2a:
0000000000000000000000000000002a
The key file for this method contains 16 bytes. Handle it as binary data. Hex text that represents 16 bytes is a different input from the 16 bytes themselves.
A two-segment example with key rotation
The owned HLS fixture generates a short MPEG-TS sample with FFmpeg. It encrypts two copies with different public test keys, using a sequence-derived IV for one and an explicit IV for the other.
The verification decrypts both segments, checks their full plaintext hashes and asks FFmpeg to decode the restored output. It also checks MPEG-TS packet alignment. Matching the original bytes is stronger evidence than “the player did not report an error.”
This fixture checks AES-128 segment processing; it is not a full HLS downloader. A complete client also follows playlist updates, discontinuities and byte ranges, and handles downloads that stop and resume.
Keep media state with the download
Save which playlist version and media sequence produced each segment. When a live playlist slides forward, an array index is not a stable identity. Use the sequence and URI together with the app’s session rules to avoid mixing segments from different runs.
Check key rotation at the exact boundary and preserve the right key for earlier downloaded segments. Refresh access through the app’s workflow when a URL expires. Retrying the same expired address does not renew it.
The buyer’s result is playable media
The final client performs the app’s access flow and produces the requested stream, download or integration output. Tests cover the media itself as well as HTTP success. Android media analysis covers adjacent formats. Send the app or the playback result you need.
Reviewed 22 October 2026 · SReverse research desk