[英]Crypto++ exception calling messageEnd
我使用以下代碼解密文件:
FileSource fe(fileUrl.c_str(), false,
new AuthenticatedDecryptionFilter(decryptor, new FileSink(
std::string(fileUrl).c_str()), CryptoPP::AuthenticatedDecryptionFilter::THROW_EXCEPTION | CryptoPP::AuthenticatedDecryptionFilter::MAC_AT_END ));
size_t BLOCK_SIZE = 16384;
while (remaining && !fe.SourceExhausted()) {
const unsigned int req = STDMIN(remaining, BLOCK_SIZE);
fe.Pump(req);
fe.Flush(false);
remaining -= req;
}
fe.MessageEnd();
如果我嘗試在沒有fe.MessageEnd()的情況下執行此操作,則我的解密文件將不足16個字節。 所以我認為我需要調用MessageEnd()來解決此問題。 但是,如果我調用MessageEnd(),則會得到以下異常:BufferedTransformation:該對象不允許輸入
如果我調用MessageEnd(),則會收到以下異常:
BufferedTransformation: this object doesn't allow input
...
正確。 FileSource
是源,並且消息必須存在。 您不能在源上調用Put
或Put2
向消息添加其他數據。
我認為您有兩種選擇可以更好地控制信號。
第一
在Source
上調用Flush
。
const int opts = AuthenticatedDecryptionFilter::THROW_EXCEPTION |
AuthenticatedDecryptionFilter::MAC_AT_END;
FileSource fe(fileUrl.c_str(), false,
new AuthenticatedDecryptionFilter(decryptor, new FileSink(
std::string(fileUrl).c_str()), opts));
fe.Flush(true);
另見的意見Flush
在過濾器::沖洗的說明書中無。
第二
將指針存放到過濾器,然后在其上調用MessageEnd
。
const int opts = AuthenticatedDecryptionFilter::THROW_EXCEPTION |
AuthenticatedDecryptionFilter::MAC_AT_END;
AuthenticatedDecryptionFilter* adf = NULL;
FileSource fe(fileUrl.c_str(), false,
adf = new AuthenticatedDecryptionFilter(decryptor, new FileSink(
std::string(fileUrl).c_str()), opts));
adf.MessageEnd();
這有點不尋常,所以我不確定您會遇到什么副作用。
不要刪除指針。 當文件FileSource
在FileSource
大括號內超出范圍時,它將刪除它。
...我的解密文件短16個字節...
我認為,如果調用Source
上的Flush
對您不起作用,則應解決此問題。
另外請記住... AuthenticatedEncryptionFilter
的輸出是2元組{ciphertext,mac}
,因此由於使用了MAC,因此得到的密文擴展為16個字節。 稍后,當您使用AuthenticatedDecryptionFilter
,將在驗證之后刪除mac。 因此,恢復的文本應與純文本大小相同,兩者均應比密文小16個字節。
我不清楚的是,事情是否按預期進行,但您沒有意識到它應該如何工作。 還是您真的在某處丟失了16字節的已恢復文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.