使用Crypto ++解码Hex编码值 [英] Decoding Hex Encoded Value with Crypto++

查看:1228
本文介绍了使用Crypto ++解码Hex编码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Cryptopp,我想编码文本和解码回来了解它的工作原理。
编码部分工作正常,但我不能得到字符串解码?始终解码的字符串为空。我在加密邮件中询问,有人说这个代码应该工作,但它不行。

I'm new to Cryptopp and I wanted to encode text and decode back to understand how it works. The encoding part works fine but I cannot get the string decoded? Always the decoded string is empty. I asked in Crypto mailing and someone said this code should work but it does not.

我想知道什么是错的。
新加入crypto我看不出有什么错误。

I would like to know what is wrong. Being new to crypto I cannot see what is wrong.

代码:

std::string encoded = m_pkey->GetValue().ToStdString();//here under debugger its ok
std::string decoded;
CryptoPP::StringSource(encoded, true, new CryptoPP::HexDecoder(new CryptoPP::StringSink(decoded)));


推荐答案

Crypto ++ wiki有很多例子,的 HexEncoder HexDecoder 类。

The Crypto++ wiki has a number of examples, including use of the HexEncoder and HexDecoder classes.

从维基:

byte decoded[] = { 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 
                   0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
string encoded;

StringSource ss(decoded, sizeof(decoded), true,
    new HexEncoder(
        new StringSink(encoded)
    ) // HexEncoder
); // StringSource

cout << encoded << endl;
...

$ ./cryptopp-test.exe
FFEEDDCCBBAA99887766554433221100

这篇关于使用Crypto ++解码Hex编码值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆