#include#include //openssl library int main() { std::string input = "Hello, World!"; unsigned char sha1[SHA_DIGEST_LENGTH]; SHA1(reinterpret_cast (input.c_str()), input.size(), sha1); std::cout << "SHA-1 hash:\n"; for (auto byte : sha1) { printf("%02x", byte); } std::cout << std::endl; return 0; }
#include#include #include #include #include std::string sha1(const std::string msg){ unsigned char *hash = SHA1((const unsigned char*)msg.c_str(), msg.length(), 0); char hexstr[41]; int i; for (i=0; i<20; i++) sprintf(hexstr+i*2, "%02x", hash[i]); hexstr[40]='\0'; std::string s(hexstr); return s; } int main(){ std::string msg = "Hello World!";//Put any message here std::string hash_msg = sha1(msg); std::cout<<"Hash of :"< In this example, we use the cpp Sha1Hash function to calculate the SHA-1 hash value of the input string. The input message is passed as an argument to the `sha1()` function, which returns the hash value as a string in hexadecimal notation. The code then prints the original message and its hash value. Package library: cpp Sha1Hash.