Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decrypt the HLS stream to a .ts file when I have the key and IV?

I have access to all the .ts files. My .m3u8 starts like this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:13
#EXT-X-KEY:METHOD=AES-128,URI="https://localserver/get_key?title_id=144", IV=0x4d1acfe1962002a4abedb8b68c65fa93
#EXTINF:12.066667,
1500_144_00000.ts
#EXTINF:9.000000,
1500_144_00001.ts
EXTINF:9.000000,
1500_144_00002.ts
...

... and the .m3u8 continues to show all the .ts files. It gives me the IV, and my Access key is f0d3321327cbaa1aa9ddba07801607442bebaad65b17ca75a15affd5

No I've been searching my brain and the web for an answer on how to decrypt the .ts files (or the concatenated file) and I have seen suggestions using both openssl and ffmpeg but I can not seem to reach all the way with either tool.

From what I've figured I can use the IV and Access_key to decrypt the stream using openssl. I have used the IV=4d1acfe1962002a4abedb8b68c65fa93 (removed 0x).

I have so far tried to with the concatenated file:

openssl aes-128-cbc -d -in concatenatedfile.ts -out decrypted_concatenatedfile.ts -nosalt -iv 4d1acfe1962002a4abedb8b68c65fa93 -K f0d3321327cbaa1aa9ddba07801607442bebaad65b17ca75a15affd5 

But this just gives me

bad decrypt
139793444538016:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:539:

I've seen suggestions that use a .key file and convert that to a readable format. But since I don't have a .key file, but a ready string, I figure this is where I fail.

I've tried using ffmpeg in accordance to this beautiful post by @aergistal.

ffmpeg -i my.m3u8 -c copy output.ts

But here too I seem to fail with my long string key.

Any suggestions on how to proceed using openssl or ffmpeg are very welcome.

Kindly

like image 274
A___ea_ Avatar asked Nov 16 '25 04:11

A___ea_


1 Answers

AES-128 means the key is 128 bits, 16 bytes, or 32 hex characters. Your string is much longer, meaning it cant be the correct key.

like image 111
szatmary Avatar answered Nov 18 '25 21:11

szatmary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!