问题
I can't find the right code to 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 ?
Thanks you !
回答1:
... convert a
CryptoPP::Integer
(from a RSA key generation) to aLPCTSTR
(I want to store the key in the registry). Could you help me ?
Something like the following should do. The Integer class overloads operator<< in integer.h
:
Integer n("0x0123456789012345678901234567890123456789");
ostringstream oss;
oss << std::hex << n;
string str(oss.str());
LPCSTR ptr = str.c_str();
The Integer class always prints a suffix when using the insertion operator. In the code above, a h
will be appended because of std::hex
. So you might want to add:
string str(oss.str());
str.erase(str.end() - 1);
Another way to do it is use the function IntToString<Integer>() from misc.h
. However, it only works on narrow strings, and not wide strings.
Integer n("0x0123456789012345678901234567890123456789");
string val = IntToString(n, 16)
IntToString
does not print the suffix. However, hacks are needed to print the string in uppercase (as shown in the manual).
来源:https://stackoverflow.com/questions/42351335/convert-cryptoppinteger-to-lpctstr