【发布时间】:2011-10-18 06:29:47
【问题描述】:
我正在尝试散列一个字符串,然后将该散列用作文件名。
我的问题: 是我遇到的所有 C++ 哈希器/加密器都对 std::string 或 char* 进行哈希处理,并将哈希处理后的字符串作为 unsigned char* 返回>?
如何将 unsigned char* 转换为 char* 或 std::string 以便将其写入文件或文件名?还是我不需要转成普通字符串就可以使用?
tstring hashString( tstring str )
{
// Post:
unsigned char hashStr[SHA256_DIGEST_SIZE];
std::string messageStr = str;
SHA256::getInstance()->digest( messageStr, hashStr );
//TCHAR *hashStrSigned = reinterpret_cast <TCHAR*>(hashStr);
// can I just use this hashStr to create a file? Or do I have to convert it to char* to use?
Handle newF = CreateFile( (LPTSTR)hashStr, GENERIC_ALL, 0, NULL, CREATE_ALWAYS,
0, NULL );
return tstring(hashStrSigned);
}
【问题讨论】:
标签: c++ winapi hash unsigned-char