HexDecoder输出为空

编程入门 行业动态 更新时间:2024-10-10 15:24:57
本文介绍了HexDecoder输出为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用cryptopp562时遇到了一些问题(在Debian上它有什么重要性)我有一个十六进制字符串,并试图将它转换为十进制int。我在cryptopp中使用HexDecoder(因为我已经在项目中使用了cryptopp)。由于我不知道在一个步骤中直接从十六进制字符串到十进制整数的方式,因此我有一个十进制字符串的中间步骤。所以它不会出现

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

然而,我的管道看起来不正确,但我不能为了我的生活找出原因。我甚至没有将十六进制字符串转换为十进制字符串,因此我的小数点int只是不断读取0.我在过去没有任何问题使用Base64Encoder(和解码器)和ZlibCompressor(和Decompressor),所以这是有点尴尬,因为它应该是更多相同。

std :: string RecoveredDecimalString; std :: string RecoveredHex =39; //十六进制,十进制为63 b $ b CryptoPP :: StringSource(RecoveredHex,true / * PumpAll * /, CryptoPP :: HexDecoder( new CryptoPP :: StringSink(RecoveredDecimalString) / * StringSink * / )/ * HexDecoder * / ); / * StringSource * /

但是就像我说的那样,在运行这个之后,RecoveredDecimalString.empty()返回true。起初,我认为这是因为我错过了泵的所有参数,但补充说没有什么区别,仍然没有任何流动。

//stackoverflow/questions/17306752/decoding-hex-encoded-value-with-cryptopp\">类似的问题在一年前被问及(并回答)了。答案回来为阅读cryptoPP wiki,但我看不到我的代码与他们wiki上的代码是不同的。

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

解决方案

std :: string RecoveredDecimalString; std :: string RecoveredHex =39; //十六进制,十进制为63 b $ b CryptoPP :: StringSource(RecoveredHex,true / * PumpAll * /, CryptoPP :: HexDecoder( new CryptoPP :: StringSink(RecoveredDecimalString) / * StringSink * / )/ * HexDecoder * / ); / * StringSource * /

命名您的 StringSource 。在更新代码时,注意 StringSource 被命名为 ss 。

std :: string已解码; std :: string encoded =39; //十六进制,所以在十进制中为63 CryptoPP :: StringSource ss(已编码,true / * PumpAll * /, new CryptoPP :: HexDecoder( new CryptoPP :: StringSink )/ * StringSink * / )/ * HexDecoder * / ); / * StringSource * /

某些GCC版本在匿名声明方面存在问题。我前段时间追踪了 StringSink 析构函数运行得太快(在数据被抽取之前)。我想提交一份GCC错误报告,但我永远无法将它缩减为最小的情况。

您也可以执行:

std :: string已解码; std :: string encoded =39; //十六进制,所以十进制数为63 CryptoPP :: HexDecoder解码器(新的CryptoPP :: StringSink(已解码)); decoder.Put(encoded.data(),encoded.size()); decoder.MessageEnd();

I'm having a bit of an issue with cryptopp562 (on Debian for what it matters) I have a hex string and am trying to convert it to a decimal int. I'm using the HexDecoder in cryptopp (since I'm already using cryptopp for other things in the project). Since I don't know of a way to go straight from a hex string to a decimal int in one step, I have an intermediate step of decimal string. So it goes

Hex string > Decimal string > Decimal int

However my pipeline appears to be incorrect, but I can't for the life of me figure out why. I'm not even getting the hex string to decimal string bit right, so my decimal int just constantly reads 0. I've used Base64Encoder (and Decoder), and ZlibCompressor (and Decompressor) in the past with no problem, so this is sort of a little embarrassing because it should just be more of the same.

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*/

But like I say, after running this, RecoveredDecimalString.empty() returns true. At first I thought it was because I'd missed off the pump all parameter, but adding that made no difference, still nothing's flowing.

A similar question was asked (and answered) a year ago. The answer came back as "read the cryptoPP wiki", but I can't see how my code is different from what's on their wiki.

What have I forgotten? I know it's going to be something very small.

解决方案

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*/

Name your StringSource. In the update to your code, notice the StringSource was named 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*/

Some versions of GCC have trouble with anonymous declarations. I tracked it down some time ago to StringSink destructors running too soon (before the data was pumped). I wanted to file a GCC bug report, but I could never get it reduced to a minimal case.

You could also perform:

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();

更多推荐

HexDecoder输出为空

本文发布于:2023-10-27 23:58:17,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   HexDecoder

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!