【问题标题】:HLS. Decrypt fmp4 segment (AES-128)HLS。解密 fmp4 段 (AES-128)
【发布时间】:2021-07-26 15:05:07
【问题描述】:

我想解密 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();

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

【问题讨论】:

    标签: encryption aes http-live-streaming poco fmp4


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 2020-04-05
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多