我試圖保存一個公共的DLIES鑰匙到內存,然後再讀它,但我不斷收到異常BER decode error
。我使用ArraySink
,ArraySource
和char[64]
緩衝區來傳輸兩個CryptoPP::DLIES<>::PublicKey
之間的密鑰。我甚至確認公鑰是好的。我錯過了什麼?從加密鑰匙從內存加密++
下面是無法正常工作的完整示例。如何修改它以便正確加載密鑰?
#include <iostream>
#include <gfpcrypt.h>
#include <filters.h>
#include <osrng.h>
int main() {
try {
CryptoPP::DefaultAutoSeededRNG rng;
CryptoPP::DLIES<>::PrivateKey privateKey;
privateKey.GenerateRandomWithKeySize(rng, 10);
CryptoPP::DLIES<>::PublicKey publicKey;
privateKey.MakePublicKey(publicKey);
if (!publicKey.Validate(rng, 3)) {
std::cout << "Something wrong with public key." << std::endl;
return 1;
}
byte buf[64];
CryptoPP::ArraySink sink(buf, 64);
publicKey.Save(sink);
CryptoPP::ArraySource source((const char *)buf, sink.TotalPutLength());
CryptoPP::DLIES<>::PublicKey pk;
pk.Load(source);
} catch (CryptoPP::Exception &ex) {
std::cout << ex.what() << std::endl;
return 1;
}
return 0;
}
我已經看到了這個問題(或它的變體)頻繁發生。另外,'ArraySource'和'ArraySink'是一種新的。我認爲他們只適用於5.6及以上版本。如果您使用5.5或更低版本,則需要使用'StringSource'和'StringSink'。和使用'DLIES'的+1。我*認爲*這是我見過它使用的唯一時間。 – jww 2014-09-24 14:31:27
我使用了DLIES,因爲我相信基於離散對數的密碼術比RSA更好(RSA,LUC)。此外,根據Crypto ++網站上的基準測試,它仍然比我真正喜歡使用的基於橢圓曲線的速度快得多。 – Xilexio 2014-09-24 20:32:41
這是否使你的Crypto ++ wiki:[橢圓曲線集成加密方案](http://www.cryptopp.com/wiki/Elliptic_Curve_Integrated_Encryption_Scheme)?它是爲'ECIES'編寫的,但適用於'DLIES' - 只需換掉'DLIES'裝備的'ECIES'裝備。並且一定要在頁面底部看到有關Bouncy Castle的註釋。 – jww 2014-09-25 06:44:28