将CryptoPP :: Integer转换为LPCTSTR [英] Convert CryptoPP::Integer to LPCTSTR
问题描述
我找不到正确的代码将CryptoPP::Integer
(从RSA密钥生成)转换为LPCTSTR
(我想将密钥存储在注册表中).你能帮我吗?
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 ?
谢谢!
推荐答案
...将
CryptoPP::Integer
(从RSA密钥生成)转换为LPCTSTR
(我要将密钥存储在注册表中).你能帮我吗?
... convert a
CryptoPP::Integer
(from a RSA key generation) to aLPCTSTR
(I want to store the key in the registry). Could you help me ?
应该执行以下操作. Integer类在integer.h
中重载 operator<<
:>
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();
使用插入运算符时,Integer类始终打印后缀.在上面的代码中,由于std::hex
,将附加 h
.因此,您可能要添加:
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);
另一种方法是使用功能 IntToString<Integer>()
来自misc.h
.但是,它仅适用于窄字符串,而不适用于宽字符串.
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
不打印后缀.但是,需要黑客才能以大写形式打印字符串(如手册中所示).
IntToString
does not print the suffix. However, hacks are needed to print the string in uppercase (as shown in the manual).
这篇关于将CryptoPP :: Integer转换为LPCTSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!