问题
Ill start by saying I dont know anything about c++ and I googled, there is nothing that can make me understand how to use SHA1 in C++. found this one though Objective C: SHA1 but its about objective c im not sure it is the same.
I need to do the following:
I habve a lot of files, i compile them by doing ./make.sh and in one file called server.cpp I need to SHA1 info_hash thats inserted in this part:
Csql_query(m_database, "insert into @files (info_hash, mtime, ctime)
values (?, unix_timestamp(), unix_timestamp())").p(i.first).execute();
so I kinda think I need to do the following sha1(?). "?" isnt info_hash i need. i think it generates somewhere and "?" is a variable.
so please dont tell me to add any classes or something else, because i do NOT understand how to do that, if i need to add something in the beggining of the file, please tell me so.
回答1:
A good library for SHA1 and other functions is cryptopp.
Here is another question where the answer is cryptopp: Fast Cross-Platform C/C++ Hashing Library
回答2:
It looks like the .p(i.first)
part already substitutes the value of i.first
into the ?
in your query. Presumably i.first
would be a value appropriate for the info_hash
column.
Without seeing more of your code, it's impossible to say for sure.
回答3:
Here is a library that implements sha1() - there are probably better ie more efficint libs but this has a good explanation of how to use it.
If you want to calculate the sha1 of a file there is a micrsoft utility to do that
来源:https://stackoverflow.com/questions/5189257/sha1-function-in-cpp-c