我正在尝试将带有 DEREncodePrivateKey 的 ECIES num0 PrivateKey 存储到 std::string 并将其重新加载到 num1 PrivateKey 对象中以进行测试。问题是当密钥在第二个 PrivateKey 对象中加载了 BERDecodePrivateKey 时,它无法被验证(也测试了未经验证的加密和解密并且没有解密)
这是代码
using namespace CryptoPP;
CryptoPP::AutoSeededRandomPool prng;
ECIES<ECP>::PrivateKey pp;
pp.Initialize(prng, ASN1::secp256k1());
/* returns true*/
bool val=pp.Validate(prng, 3);
std::string saves;
StringSink savesink(saves);
pp.DEREncodePrivateKey(savesink);
/*additional unnecessary steps to make sure the key is written completely */
savesink.MessageEnd();
savesink.Flush(true);
ECIES<ECP>::PrivateKey pro;
StringSource savesSource(saves, true);
pro.BERDecodePrivateKey(savesSource,true,savesSource.MaxRetrievable());
/*here the exception is thrown */
pro.ThrowIfInvalid(prng, 3);