#include <iostream>
#include <openssl/sha.h>
#include <string>
#include <string.h>
#include <vector>
#include <fstream>
using namespace std;
std::vector<char> readfile(const char* filename) {
std::vector<char> data;
std::fstream fs;
fs.open(filename, std::ios::in);
char buffer;
while (!(fs.eof()) && fs.get(buffer)) {
data.push_back((char)buffer);
}
fs.close();
return data;
}
int main(int argc, char**argv)
{
unsigned char md[33] = {0};
vector<char> filedata = readfile(argv[1]);
SHA256((const unsigned char *)filedata.data(), filedata.size(), md);
string sha256_res = "";
char buf[3] = {0};
for(int i = 0; i < 32; i++ )
{
sprintf(buf,"%02x", md[i]);
sha256_res.append(buf);
}
cout << sha256_res << endl;
return 0;
}