HLS解密 fmp4 段 (AES-128)

问题描述

我想解密 fmp4 段。 此段已使用 HLS Apple 工具 (https://developer.apple.com/documentation/http_live_streaming/about_apple_s_http_live_streaming_tools) 进行加密

方法是 AES-128

IV 是 1d48fc5dee84b5a3e9a428f055e03c2e

我有一把钥匙和 IV(你可以得到钥匙,然后在谷歌驱动器中分段 https://drive.google.com/drive/folders/1xF-C9EXFvT8qjI--sBB6QMPn8cNW7L-D?usp=sharing

我使用 Poco 库解密。

这是我的代码:

    Poco::Crypto::Cipher::ByteVec readKey(const std::string& uri) {
        Poco::Crypto::Cipher::ByteVec key;

        auto stream = Stream::makeStream(uri);
        if (stream->open(uri,{})) {
            key.resize(KEY_SIZE);
            stream->read((char*)&key[0],KEY_SIZE);
        }

        return key;
    }


std::vector<uint8_t> _key = readKey("./unit-tests/resources/cipher-stream/file.key");

std::string ivSrc = "1d48fc5dee84b5a3e9a428f055e03c2e";
Poco::Crypto::Cipher::ByteVec iv {ivSrc.begin(),ivSrc.end()};
Poco::Crypto::CipherKey key("aes-128-cbc",_key,iv);
Poco::Crypto::Cipher::Ptr cipher = Poco::Crypto::CipherFactory::defaultFactory().createCipher(key);

Poco::FileInputStream src("./unit-tests/resources/cipher-stream/fileSequence1.m4s");
Poco::FileOutputStream dst("./unit-tests/resources/cipher-stream/fileSequence1_dec.m4s");

Poco::Crypto::CryptoOutputStream decryptor(dst,cipher->createDecryptor());
Poco::StreamCopier::copyStream(src,decryptor);

// decryptor.close();
src.close();
dst.close();

问题描述: 解密后,我得到了扭曲的数据。您可以在文件的开头看到这一点。请看下图。右侧的图像文件被扭曲。 您可以在左侧看到正确的数据。

enter image description here

解决方法

您使用了错误的 IV;这将导致第一个块(16 个字节)被破坏。您的 IV hex 值为 1d48fc5dee84b5a3e9a428f055e03c2e,但您将其解释为 ASCII。它使用字符串的前 16 个字节并忽略其余字节。

我很长时间没有使用 Poco,不记得是否有方便的十六进制解析器,但这正是您所需要的。或者直接用十六进制而不是 ASCII 字符串写出 IV。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...