Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

string - Running certutil -hashfile with standard inputs for filepath and hashtype (c++)

First time posting. I am trying to write a simple program that takes a file path and a hash type from standard input, and outputs the corresponding hash using certutil. Later I would like to compare the hash to one that the user enters, and output a pass or fail statement.

#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<<"
Filepath is: "<<path_to_file;
cout<<"
Which hash to use? (e.g SHA256)"<<endl;
cin>>hash_type;
cout<<"
Hash type is: "<<hash_type<<endl;

I have tried with or without the cout;

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

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

This will run perfectly fine, and I see the resultant hash. I just can't seem to use the strings from standard input. I suspect it could have something to do with the extra backslash needed in the filepath or another delimiter?

return 0;
}

I'm still learning about pointers, but I have also tried the following; system("certutil -hashfile *path_to_file *hash_type"); since I am getting the following error:

Certutil: -hashfile command FAILED: 0x80070002 Certutil: The system cannot find the file specified. 'hash_type' is not recognised as an internal or external command, operable program or batch file

I would appreciate any help. Thanks in advance.

question from:https://stackoverflow.com/questions/65852814/running-certutil-hashfile-with-standard-inputs-for-filepath-and-hashtype-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have got it working.

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

This was very helpful: cannot convert 'std::basic_string<char>' to 'const char*' for argument '1' to 'int system(const char*)'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...