使用 .m3u8 解密和组合 .ts 音频文件 [英] Decrypting And Combining .ts Audio Files with .m3u8

查看:114
本文介绍了使用 .m3u8 解密和组合 .ts 音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几千个 .ts AES-128 加密音频文件,带有 .key 和 .m3u8 文件.

I have a few thousand .ts AES-128 encrypted audio files with a .key and .m3u8 file.

密钥文件只包含一个由 44 个字符组成的密钥..m3ud 文件似乎是某种类型的播放列表.

The key file just contains a key comprised of 44 characters. The .m3ud files appears to be some type of playlist.

#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="http://localhost:[port]/hls/keys/nax_9781843794066.key"
#EXTINF:10,
http://localhost:[port]/filesequence0000000.ts
#EXTINF:10,
etc...

请注意,.ts 文件的密钥 URI 和路径现在都是错误的.

Note that both the key URI and path to the .ts files is now wrong.

环顾四周,看来 ffmpeg 可能适用于这种格式.但我不确定语法.

Looking around, it appears ffmpeg might work with this format. But I am unsure of the syntax.

如何解密和合并这些文件?

How can I decrypt and combine these files?

我一直在尝试修复播放列表语法并弄清楚如何使用 ffmpeg 并得到了.

I have been playing around with fixing the playlist syntax and figuring out how to use ffmpeg and got to.

ffmpeg -i nax_9781843794066.m3u8 -c copy output.ts
ffmpeg version N-77197-gdf2ce13 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil      55. 10.100 / 55. 10.100
libavcodec     57. 17.100 / 57. 17.100
libavformat    57. 19.100 / 57. 19.100
libavdevice    57.  0.100 / 57.  0.100
libavfilter     6. 20.100 /  6. 20.100
libswscale      4.  0.100 /  4.  0.100
libswresample   2.  0.101 /  2.  0.101
libpostproc    54.  0.100 / 54.  0.100
[hls,applehttp @ 0000003e6348a660] Error when loading first segment 'filesequence0000000.ts'
nax_9781843794066.m3u8: Invalid data found when processing input

filesequence0000000.ts 是同一个文件夹中的第一个文件.我不知道这是加密问题还是其他问题.

filesequence0000000.ts is the first file, in the same folder. I cannot tell if this is some problem with the encryption or something else.

这是关键文件,如果重要的话:MoOoNvcKlThWBm2T+VzYq9QKZLw7MFUqSyLYjiwquTQ=

This is the key file, if it matters: MoOoNvcKlThWBm2T+VzYq9QKZLw7MFUqSyLYjiwquTQ=

推荐答案

今天我有几个小时的空闲时间,并且玩弄了这个.长话短说 - base64 密钥是 AES 加密的.这种额外的加密是使用从设备数据动态生成的密钥完成的……这意味着即使我拥有您设备中的整个数据文件夹,我也无法解密它.

I've had few free hours today and toyed with this. Long story short - that base64 key is AES encrypted. This additional encryption is done with key which is dynamically generated from device data... meaning that even if I have whole data folder from your device I wouldn't be able to decrypt it.

现在,当您拥有带有离线数据的 root 设备时,这是另一回事 - 您显然可以注入代码以在解密时拦截密钥,以便内容可以开始播放......我就是这样得到的.

Now, when you posses rooted device with offline data that's another matter - you can obviously inject your code to intercept key when it's decrypted so content can start playing... which is how I got it.

当您拥有正确的密钥时,*.ts 文件的解密和连接是微不足道的.我建议您使用 FFMPEG 来完成这项任务,我的 C# 代码我要离开以进行说明,仅在某些情况(取决于文件的编码方式)下才有效:

When you have proper key, decryption and joining of *.ts files is trivial. I recommend that you use FFMPEG for this task, my C# code that I'm leaving for illustration works well works only in some cases (depending on how files are encoded):

var folder = "path_to_folder";
byte[] encryptionKey = File.ReadAllBytes(folder + "path_to_key.key");

var outputFile = "c:\i_love_you_guys.ts";
using (FileStream outputFileStream = new FileStream(outputFile, FileMode.Create))
{
    var files = Directory.GetFiles(folder, "*.ts");
    for (int i = 0; i < files.Length; i++)
    {
        byte[] encryptionIV = new byte[16];
        using (FileStream inputFileStream = new FileStream(files[i], FileMode.Open))
        {
            using (var aes = new AesManaged { Key = encryptionKey, IV = encryptionIV, Mode = CipherMode.CBC })
            using (var encryptor = aes.CreateDecryptor())
            using (var cryptoStream = new CryptoStream(inputFileStream, encryptor, CryptoStreamMode.Read))
            {
                cryptoStream.CopyTo(outputFileStream);
            }
        }
    }
}

所以,结果证明这是一场野鹅追逐.只要您拥有正确的 my.key,@aergistal 在他的回答中所说的就是完全有效的.因此专注于获取明文格式的密钥和解密将变得非常容易.

So, this turned out to be wild goose chase. What @aergistal says in his answer is completely valid as long as you have proper my.key. Thus focus on obtaining key in plain format and decryption will then be super easy.

这篇关于使用 .m3u8 解密和组合 .ts 音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆