c++ - 如何在 Crypto++ 中将 base64 转换为整数?

标签 c++ base64 crypto++ bigint

我使用 Crypto++ 库。我有一个保存为 CString 的 base64 字符串。我想将我的字符串转换为整数。实际上这个 base64 是从一个 Integer 构建的,现在我想再次转换为 Integer。但是两个 Integer 不相等。换句话说,第二个 Integer 不等于原始 Integer。

Base64Decoder bd;
CT2CA s(c);
std::string strStd(s);

bd.Put((byte*)strStd.data(), strStd.size());
bd.MessageEnd();

word64 size = bd.MaxRetrievable();
vector<byte> cypherVector(size);

string decoded;
if (size && size <= SIZE_MAX)
{
    decoded.resize(size);
    bd.Get((byte*)decoded.data(), decoded.size());
}

Integer cipherMessage((byte*)decoded.data(), decoded.size());

最佳答案

string decoded;
if (size && size <= SIZE_MAX)
{
    decoded.resize(size);
    bd.Get((byte*)decoded.data(), decoded.size());
}

您有一个名为decoded 的字符串,但您实际上从未通过Base64Decoder 运行它来解码数据。 .

使用类似下面的东西。我没有方便测试的 MFC 项目,所以我假设您已将 CString 转换为 std::string

// Converted from Unicode CString
std::string str;

StringSource source(str, true, new Base64Decoder);
Integer value(val, source.MaxRetrievable());
std::cout << std::hex << value << std::endl;

StringSource 是一个BufferedTransformationInteger 构造函数 you are using is :

Integer (BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED, ByteOrder order=BIG_ENDIAN_ORDER)

StringSourceInteger 之间是Base64Decoder。它是一个过滤器,可以即时解码字符串。因此数据从源(StringSource)流向接收器(Integer 构造函数)。

另见 Pipelines在 Crypto++ wiki 上。

关于c++ - 如何在 Crypto++ 中将 base64 转换为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41800218/

相关文章:

reactjs - 在 ReactJS 中将 PDF 编码为 base64

c++ - 使用Crypto++生成指定范围内的随机数

java - 将 ECIES ECP CryptoPP 转换为 JAVA

c++ - 如何不使用单例?

c++ - 在 DirectX 11 中渲染世界空间线

c++ - ctime std::命名空间冲突

c++ - 在 C++ 中将 unordered_map 与自定义值对象一起使用

c# - 解码Base64图像

delphi - 如何将电子邮件附件保存到文件

c++ - Crypto++/iOS 64 位项目中的 undefined symbol