簡體   English   中英

HLS。 解密 fmp4 段 (AES-128)

[英]HLS. Decrypt fmp4 segment (AES-128)

我想解密 fmp4 段。 此段已使用 HLS Apple Tools 加密( 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();

問題描述:解密后數據失真。 您可以在文件的開頭看到這一點。 請看下圖。 右側的圖像文件被扭曲。 您可以在左側看到正確的數據。

在此處輸入圖片說明

您使用了錯誤的 IV; 這將導致第一個塊(16 個字節)被破壞。 您的 IV十六進制值為 1d48fc5dee84b5a3e9a428f055e03c2e,但您將其解釋為 ASCII。 它使用字符串的前 16 個字節並忽略其余字節。

我很久沒有使用 Poco 了,不記得是否有一個方便的十六進制解析器,但這就是你所需要的。 或者直接用十六進制而不是 ASCII 字符串寫出 IV。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM