Last active
April 21, 2022 22:32
-
-
Save odds-get-evened/1673674a0b566372a22173c29f52fb69 to your computer and use it in GitHub Desktop.
toying with c++ hashing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <openssl/sha.h> | |
#include <sstream> | |
#include <string> | |
#include <iomanip> | |
using namespace std; | |
string sha256_simple(const string s) | |
{ | |
unsigned char hash[SHA256_DIGEST_LENGTH]; | |
SHA256_CTX ctx; | |
SHA256_Init(&ctx); | |
SHA256_Update(&ctx, s.c_str(), s.size()); | |
SHA256_Final(hash, &ctx); | |
stringstream ss; | |
for(int i=0; i<SHA224_DIGEST_LENGTH; i++) | |
{ | |
ss << hex << setw(2) << setfill('0') << (int) hash[i]; | |
} | |
return ss.str(); | |
} | |
int main() | |
{ | |
cout << sha256_simple("value is soul!") << endl; | |
cout << sha256_simple("hi there") << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment