我正在尝试散列一个字符串,然后使用该散列作为文件名。
我的问题:我遇到的所有 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);
}