加密ts文件解密

#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://j-island.net/movie/hls_key/s/857401e309d8a032c3bb18f4b09b8db2/?f=jj_20190401_hihijets_004",IV=0xaa3dcf6a7acb92ff4fb08d9b3b3d6f51
#EXTINF:12.078733,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400000.ts
#EXTINF:9.009000,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400001.ts
#EXTINF:9.009000,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400002.ts
#EXTINF:12.012000,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400003.ts
#EXTINF:9.009000,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400004.ts
#EXTINF:2.002000,
https://j-island.stream2.johnnys-net.jp/j-island/jj_20190401_hihijets_004/jj_20190401_hihijets_00400005.ts
#EXT-X-ENDLIST

m3u8视频另一种下载方式
如上图中用ts链接直接下载下来的ts视频文件是加密的(为什么要下加密的?虽然加密但是下载速度快啊)。

#EXT-X-KEY 字段已经写明了加密方式是AES-128,key通过URI获取,IV也有。

#EXT-X-KEY:
METHOD=AES-128,
URI="https://j-island.net/movie/hls_key/s/857401e309d8a032c3bb18f4b09b8db2/?f=jj_20190401_hihijets_004",
IV=0xaa3dcf6a7acb92ff4fb08d9b3b3d6f51

那怎么解密呢?
1.复制URI地址到网页,你将秒速自动下载得到一个16字节文件
2.打开终端,打开该文件查看16进制:

  • 打开二进制key
vi -b /路径/key文件
  • 输入“ :%!xxd”再把二进制文件切换到16进制
00000000: 283d cc2d 3747 e965 0a81 ead3 1e04 fa8a  (=.-7G.e........

获取到key就是 283dcc2d3747e9650a81ead31e04fa8a
3.打开终端,转化

openssl aes-128-cbc -d -in /路径/media_0.ts -out /路径/media_decryptd_0.ts -nosalt -iv $iv -K $strkey

media_0.ts : 加密ts文件(无法播放)
media_decryptd_0.ts : 解密后ts文件(可以直接播放)
$iv : aa3dcf6a7acb92ff4fb08d9b3b3d6f51(#EXT-X-KEY字段中获取,注意去掉0x)
$strkey : 283dcc2d3747e9650a81ead31e04fa8a(上一步获得)

例子:

openssl aes-128-cbc -d -in /Users/用户名/Downloads/001.ts -out /Users/用户名/Downloads/001_dec.ts -nosalt -iv aa3dcf6a7acb92ff4fb08d9b3b3d6f51 -K 283dcc2d3747e9650a81ead31e04fa8a

命令执行完秒速转化(也可能我文件特别短,都切成ts了,一般都不长吧……
4.到对应路径下去,就能看到转化成功到ts视频了
(还是直接用ffmpeg转化下载比较方便,可以参见Mac直接下载m3u8成mp4[追星技能]这篇)
ps:环境是MacOS