请注意,本文需要首先安装openssl和ffmpeg。查看方法:
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ openssl version
OpenSSL 1.1.1f 31 Mar 2020
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ ffmpeg -version
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
如果没有安装,安装方法:
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/ts$ sudo apt-get install ffmpeg
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ sudo apt-get install openssl
https://blog.csdn.net/oncealong/article/details/82785642
20210806(在ubuntu20.04下)hls视频的加解密示例(注解)
oncealong 2018-09-20 13:49:44 4636 收藏 5
hls的加密采用aes-128-cbc, 关于aes-128-cbc, 请参考前文使用openssl命令加解密 aes-128-cbc的简单示例.
获取加密用16字节key, 并查看其值.
openssl rand 16 > enc.key
xxd enc.key
00000000: 598b a998 f204 f30c b900 4de6 7060 0b33 Y…M.p`.3
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~$ cd aes128/
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ ll
total 61764
drwxr-xr-x 2 rootroot rootroot 4096 8月 6 20:07 ./
drwxr-xr-x 41 rootroot rootroot 4096 8月 6 20:07 ../
-rwxr--r-- 1 rootroot rootroot 63238115 7月 8 09:40 13.mp4*
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ openssl rand 16 > enc.key
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ xxd enc.key
00000000: 1866 6dff 9b6b f41e d785 137b 170e 5ffe .fm..k.....{.._.
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
获取加密用iv并查看其值.
openssl rand -hex 16 > enc.iv.txt
xxd enc.iv.txt
00000000: 6139 6238 3031 3366 3830 3966 3334 6330 a9b8013f809f34c0
00000010: 3330 3839 3932 3066 6633 3461 6566 3765 3089920ff34aef7e
00000020: 0a .
cat enc.iv.txt
a9b8013f809f34c03089920ff34aef7e
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ openssl rand -hex 16 > enc.iv.txt
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ ll
total 61772
drwxr-xr-x 2 rootroot rootroot 4096 8月 6 20:08 ./
drwxr-xr-x 41 rootroot rootroot 4096 8月 6 20:07 ../
-rwxr--r-- 1 rootroot rootroot 63238115 7月 8 09:40 13.mp4*
-rw-rw-r-- 1 rootroot rootroot 33 8月 6 20:08 enc.iv.txt
-rw-rw-r-- 1 rootroot rootroot 16 8月 6 20:07 enc.key
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ cat enc.iv.txt
1daff027711cf04362064325fdd29b76
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ xxd enc.iv.txt
00000000: 3164 6166 6630 3237 3731 3163 6630 3433 1daff027711cf043
00000010: 3632 3036 3433 3235 6664 6432 3962 3736 62064325fdd29b76
00000020: 0a .
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ touch enc.keyinfo
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
生成hls_key_info_file. 其内容形式如下:
Key URI
Path to key file
IV (optional)
网页链接
解码的K参数:-K
解码的iv参数:-iv
vim enc.keyinfo
https://me.test.com/get_dk
enc.key
a9b8013f809f34c03089920ff34aef7e
https://me.test.com/get_dk
enc.key
1daff027711cf04362064325fdd29b76
使用ffmpeg生成加密hls视频
ffmpeg -y \
-i mp4_sample.mp4 \
-hls_key_info_file enc.keyinfo \
-hls_playlist_type vod \
-hls_segment_filename "fileSequence%d.ts" \
prog_index.m3u8
ffmpeg -y -i mp4_sample.mp4 -hls_key_info_file enc.keyinfo -hls_playlist_type vod -hls_segment_filename "fileSequence%d.ts" prog_index.m3u8
ffmpeg -y -i 13.mp4 -hls_key_info_file enc.keyinfo -hls_playlist_type vod -hls_segment_filename "fileSequence%d.ts" prog_index.m3u8
解密
选择 fileSequence0.ts 来解密
ls -a fileSequence*
使用openssl 解密ts视频. 这里的iv, K都是加密时设定的.
openssl aes-128-cbc -d -in fileSequence0.ts -out fileSequence0_decrypto.ts -nosalt -iv a9b8013f809f34c03089920ff34aef7e -K 598ba998f204f30cb9004de670600b33
(出错了!请严重注意,一定要及时删除出错的视频:fileSequence0_decrypto.ts!!!!)
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$ openssl aes-128-cbc -d -in fileSequence0.ts -out fileSequence0_decrypto.ts -nosalt -iv a9b8013f809f34c03089920ff34aef7e -K 598ba998f204f30cb9004de670600b33
bad decrypt
140151805687104:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:610:
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/aes128$
openssl aes-128-cbc -d -in fileSequence0.ts -out fileSequence0_decrypto.ts -nosalt -iv 1daff027711cf04362064325fdd29b76 -K 18666dff9b6bf41ed785137b170e5ffe
得到的fileSequence0_decrypto.ts即是解密视频。(一个6秒钟的切片视频!)
参考列表:
http://hlsbook.net/how-to-encrypt-hls-video-with-ffmpeg/
https://blog.csdn.net/nizhengjia888/article/details/78041945
参考资料:
https://blog.csdn.net/oncealong/article/details/82785642
hls视频的加解密示例
https://blog.csdn.net/nizhengjia888/article/details/78041945
解密HLS中的AES加密
https://blog.csdn.net/oncealong/article/details/82785447
使用openssl命令加解密 aes-128-cbc的简单示例
https://blog.csdn.net/ddddfang/article/details/92838200
xxd命令
https://blog.csdn.net/y534560449/article/details/116531326
!!!!使用 FFmpeg 生成 ts 切片并使用 AES-128 加密
https://blog.csdn.net/beyond706/article/details/111772810
!!!!使用openssl m3u8解密 EXT-X-KEY:METHOD=AES-128,URI=xxx
https://blog.csdn.net/u014470361/article/details/90705336
ubuntu16.04安装ffmpeg最新版
https://blog.csdn.net/huangjingshui/article/details/75003771
如何查看openssl版本号
openssl version
openssl version -a