C++ 解码器输出为空

C++ 解码器输出为空,c++,hex,pipeline,crypto++,C++,Hex,Pipeline,Crypto++,我对cryptopp562有点问题(在Debian上,这很重要),我有一个十六进制字符串,并试图将其转换为十进制整数。我在cryptopp中使用了HexDecoder(因为我已经在项目中的其他东西中使用cryptopp)。因为我不知道如何在一个步骤中直接从十六进制字符串转换成十进制整数,所以我有一个十进制字符串的中间步骤。就这样 十六进制字符串>十进制字符串>十进制整数 然而,我的管道似乎是不正确的,但我不能为我的生活找出原因。我甚至没有把十六进制字符串转换成十进制字符串,所以我的十进制int值

我对cryptopp562有点问题(在Debian上,这很重要),我有一个十六进制字符串,并试图将其转换为十进制整数。我在cryptopp中使用了HexDecoder(因为我已经在项目中的其他东西中使用cryptopp)。因为我不知道如何在一个步骤中直接从十六进制字符串转换成十进制整数,所以我有一个十进制字符串的中间步骤。就这样

十六进制字符串>十进制字符串>十进制整数

然而,我的管道似乎是不正确的,但我不能为我的生活找出原因。我甚至没有把十六进制字符串转换成十进制字符串,所以我的十进制int值总是读取0。我在过去使用Base64编码器(和解码器)和ZlibCompressor(和解压缩器)都没有问题,所以这有点尴尬,因为它应该更相似

std::string RecoveredDecimalString;
std::string RecoveredHex = "39"; //Hex, so would be 63 in decimal
CryptoPP::StringSource (RecoveredHex, true /*PumpAll*/,
    new CryptoPP::HexDecoder(
        new CryptoPP::StringSink(RecoveredDecimalString) /*StringSink*/
    )/*HexDecoder*/
);/*StringSource*/
但正如我所说,运行此命令后,RecoveredDecimalString.empty()返回true。起初我认为这是因为我错过了泵的所有参数,但加上这没有什么区别,仍然没有流动

。答案是“阅读cryptoPP维基”,但我看不出我的代码与他们维基上的代码有什么不同

我忘了什么?我知道这将是一件非常小的事情

std::string RecoveredDecimalString;
std::string RecoveredHex = "39"; //Hex, so would be 63 in decimal
CryptoPP::StringSource (RecoveredHex, true /*PumpAll*/,
    new CryptoPP::HexDecoder(
        new CryptoPP::StringSink(RecoveredDecimalString) /*StringSink*/
    )/*HexDecoder*/
);/*StringSource*/
命名您的
StringSource
。在代码更新中,请注意
StringSource
被命名为
ss

std::string decoded;
std::string encoded = "39"; //Hex, so would be 63 in decimal
CryptoPP::StringSource ss(encoded, true /*PumpAll*/,
    new CryptoPP::HexDecoder(
        new CryptoPP::StringSink(decoded) /*StringSink*/
    )/*HexDecoder*/
);/*StringSource*/
GCC的某些版本在匿名声明方面有问题。不久前,我跟踪到
StringSink
析构函数运行得太快(在数据被抽取之前)。我想提交一份GCC错误报告,但我无法将其缩减到最低限度

您还可以执行以下操作:

std::string decoded;
std::string encoded = "39"; //Hex, so would be 63 in decimal

CryptoPP::HexDecoder decoder(new CryptoPP::StringSink(decoded));
decoder.Put(encoded.data(), encoded.size());
decoder.MessageEnd();

在对CryptoC++一无所知的情况下,它只构造一个(临时的)
CryptoPP::StringSource
对象。您不需要执行一些操作(即调用一些成员函数)来真正实现转换吗?我不需要对CryptoPP的其他部分执行这些操作,但我想我还是会尝试您的建议,但是
CryptoPP::StringSource HexSource(RecoveredHex,true/*PumpAll*/,new CryptoPP::HexDecoder(new CryptoPP::StringSink(RecoveredDecimalString));
不幸的是仍然产生了空输出。“阅读cryptoPP wiki”-我没有这么说;我提供了wiki的一个工作示例(我还编写了wiki示例)。有趣的是,这似乎解决了这个问题。我不知道GCC的某些版本有这个问题,但当我想到,上次我这么做时,它是在Windows(VS 2008)中。这是几年前迁移到Debian后我第一次使用匿名声明,所以我需要注意。谢谢!