代码:
try { //读取的加密视频ts文件路径 byte[] encodeBuffer = File.ReadAllBytes("C:\\Users\\admin\\Downloads\\322251.ts"); /// A216DF0DA0082028163781ECC258BA5B代表winhex看到的字符串 32734893fb097a767c9ea903936a6d8b代表m3u8文件中的iv偏移 byte[] decodeBuffer = Decrypt(encodeBuffer, "A216DF0DA0082028163781ECC258BA5B", "32734893fb097a767c9ea903936a6d8b"); //将ts视频文件解密mp4文件保存 File.WriteAllBytes("C:\\Users\\admin\\Downloads\\322251解密后的视频.mp4", decodeBuffer); } catch (Exception ex) { Debug.WriteLine(ex.Message); Console.WriteLine(ex.Message); }
拿到key文件对应的key
拿到key 拿到偏移量iv
代码
public static byte[] Decrypt(byte[] cipherTextBytes, string key16, string iv16) { // 确保字符串长度是偶数 if (key16.Length % 2 == 1) { throw new ArgumentException("The hex string length must be even."); } if (iv16.Length % 2 == 1) { throw new ArgumentException("The hex string length must be even."); } byte[] buffkey = new byte[key16.Length / 2]; for (int i = 0; i < key16.Length; i += 2) { var tempkey = key16.Substring(i, 2); buffkey[i / 2] = Convert.ToByte(tempkey, 16); } byte[] buffiv = new byte[key16.Length / 2]; for (int i = 0; i < iv16.Length; i += 2) { var tempkey = iv16.Substring(i, 2); buffiv[i / 2] = Convert.ToByte(tempkey, 16); } // 确保密钥和IV长度正确(128位,即16字节) byte[] keyBytes = buffkey.ToArray(); byte[] ivBytes = buffiv.ToArray(); // 创建RijndaelManaged对象用于解密 using (RijndaelManaged aes = new RijndaelManaged()) { aes.Key = keyBytes; aes.IV = ivBytes; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; // 创建解密器 ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); // 创建MemoryStream以用于解密 using (MemoryStream msDecrypt = new MemoryStream(cipherTextBytes)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { // 读取解密后的字节 byte[] decryptedBytes = new byte[cipherTextBytes.Length]; csDecrypt.Read(decryptedBytes, 0, decryptedBytes.Length); return decryptedBytes; } } } }
写个C#控制台,粘贴程序,修改参数就可以跑了
附录一张图片
标签:aes,m3u8,C#,解密,Length,key16,视频文件,new,byte From: https://www.cnblogs.com/JohnnyLei/p/18147699