使用标准的文件路径和哈希类型输入运行certutil -hashfile (c++)



首次发布。我试图编写一个简单的程序,从标准输入中获取文件路径和哈希类型,并使用certutil输出相应的哈希。稍后,我想将该哈希值与用户输入的哈希值进行比较,并输出一个通过或失败语句。

#include <iostream>
#include <string>
using namespace std;
int main() {
string hash_type;
string path_to_file;
cout<<"Enter full file path to hash: "<<endl;
cin>>path_to_file;
cout<<"nFilepath is: "<<path_to_file;
cout<<"nWhich hash to use? (e.g SHA256)"<<endl;
cin>>hash_type;
cout<<"nHash type is: "<<hash_type<<endl;

我试过有或没有计数;

cout<<system("certutil -hashfile path_to_file hash_type");  

system("certutil -hashfile C:UsersmooseDesktopcurrent.cpp SHA256")

这将运行得很好,我看到了结果哈希。我似乎不能使用标准输入的字符串。我怀疑这可能与文件路径中需要的额外反斜杠或其他分隔符有关?

return 0;
}

我还在学习指针,但我也尝试了以下;System ("certutil -hashfile *path_to_file *hash_type");因为我得到以下错误:

Certutil: -hashfile command FAILED: 0x80070002Certutil:系统找不到指定的文件。'hash_type'不能被识别为内部或外部命令、可操作程序或批处理文件

我将感激任何帮助。提前谢谢。

我已经让它工作了。

string hash_args = "certutil -hashfile " + path_to_file + " " + hash_type;
system(hash_args.c_str());

这是非常有用的:std::basic_string'const char*'对于论证'1'int system(const char*)'

最新更新