将 CryptoPP::Integer 转换为 LPCTSTR

Convert CryptoPP::Integer to LPCTSTR

我找不到将 CryptoPP::Integer(从 RSA 密钥生成)转换为 LPCTSTR(我想将密钥存储在注册表中)的正确代码。你能帮帮我吗?

谢谢!

... convert a CryptoPP::Integer (from a RSA key generation) to a LPCTSTR (I want to store the key in the registry). Could you help me ?

像下面这样的事情应该做。整数 class 在 integer.h:

中重载了 operator<<
Integer n("0x0123456789012345678901234567890123456789");
ostringstream oss;    
oss << std::hex << n;

string str(oss.str());
LPCSTR ptr = str.c_str();

Integer class 在使用插入运算符时总是打印后缀。在上面的代码中,由于std::hex,将附加一个h。所以你可能想添加:

string str(oss.str());
str.erase(str.end() - 1);

另一种方法是使用 misc.h 中的函数 IntToString<Integer>()。但是,它只适用于窄字符串,而不适用于宽字符串。

Integer n("0x0123456789012345678901234567890123456789");
string val = IntToString(n, 16)

IntToString 不打印后缀。但是,需要 hack 才能以大写形式打印字符串(如手册中所示)。