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<<"\nFilepath is: "<<path_to_file;
cout<<"\nWhich hash to use? (e.g SHA256)"<<endl;
cin>>hash_type;
cout<<"\nHash 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:\Users\moose\Desktop\current.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.
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*)'
User contributions licensed under CC BY-SA 3.0