使用.m3u8解密和组合.ts音频文件

时间:2015-12-12 02:03:13

标签: encryption ffmpeg

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

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

#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...

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

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

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

我一直在玩修复播放列表语法并弄清楚如何使用ffmpeg并开始使用。

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是同一文件夹中的第一个文件。我不知道这是加密还是别的问题。

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

3 个答案:

答案 0 :(得分:10)

ffmpeg的最新版本应该能够解密AES-128 HLS流。您不需要网络服务器。如果m3u8 URI /路径错误,您可以:

  • 创建目录
  • 将密钥复制到密钥文件,即my.key,并将其放在目录中。请注意,如果播放列表有多个键,则可以旋转键,将所有键复制到不同的文件中。
  • 将所有.ts段复制到同一个目录
  • 复制并编辑playlist.m3u8,并仅使用密钥(URI)和段的文件名。
  • 获取单个.ts文件:

    ffmpeg -i playlist.m3u8 -c copy output.ts
    
  • 如果您只想要没有.ts容器的音频流,则可以将其解压缩。例如:假设您使用AAC编解码器运行时有一个音频流:

    ffmpeg -i playlist.m3u8 -map 0:a -c copy output.aac
    

这会将AAC流提取到文件而不进行重新编码。如果你想要一个与你的源不同的编解码器,你将不得不重新编码。

如果出于某种原因,您必须使用openssl来解密细分,请注意,如果未指定IV,则IV等于细分受众群的媒体顺序,即。第一个分段有IV=0,第二个分段有IV=1,依此类推。解密后,更新播放列表以指向解密的段并删除EXT-X-KEY行。如果您走这条路线,您甚至不需要ffmpeg来获取单个.ts文件,因为MPEG-TS可以直接连接,即。你可以在解密的段上使用cat

答案 1 :(得分:3)

我今天的休息时间很少,玩弄了这个。长话短说 - base64密钥是AES加密的。这个额外的加密是通过从设备数据动态生成的密钥完成的......意味着即使我的设备中有整个数据文件夹,我也无法解密它。

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

如果你有正确的密钥,解密和加入* .ts文件是微不足道的。 我建议您use FFMPEG for this task ,我要离开插图的C#代码仅适用于某些情况(取决于文件的编码方式):

 composer require laravel/laravel:^5.4.0 --update-with-dependencies
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package laravel/laravel No version set (parsed as 1.0.0) is satisfiable by laravel/laravel[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.
  Problem 2
    - laravel/laravel v5.5.0 requires php >=7.0.0 -> your PHP version (5.6.30) does not satisfy that requirement.
    - laravel/laravel v5.4.9 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.30 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.3 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.23 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.21 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.19 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.16 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.15 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.0 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - Installation request for laravel/laravel ^5.4.0 -> satisfiable by laravel/laravel[v5.4.0, v5.4.15, v5.4.16, v5.4.19, v5.4.21, v5.4.23, v5.4.3, v5.4.30, v5.4.9, v5.5.0].

所以,事实证明这是一场疯狂的追逐。 @aergistal在他的回答中说的是完全有效的,只要你有适当的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); } } } } 。因此,专注于以普通格式获取密钥和解密将非常容易。

答案 2 :(得分:0)

我对此代码有一个疑问:

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);
            }
        }
    }
}

如何单独解密而不是单个文件输出?