Created
December 10, 2018 18:11
-
-
Save frank9615/c28d3f396801db2352ca66b7c88c6137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Calculate SHA1 | |
* @Compile with -lcrypto | |
* _________________________________________________________________ | |
* |Openssl MacOs install | | |
* ----------------------------------------------------------------- | |
* |brew install openssl | | |
* |brew link --force openssl | | |
* |ln -s /usr/local/opt/openssl/include/openssl /usr/local/include| | |
* ----------------------------------------------------------------- | |
* | |
* Francesco Accardi | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <openssl/sha.h> | |
int main(){ | |
char data[] = "test"; | |
size_t length = strlen(data); | |
unsigned char hash[SHA_DIGEST_LENGTH]; | |
SHA1((const unsigned char*)data, length, hash); | |
// hash now contains the 20-byte SHA-1 hash | |
for(int i=0;i<SHA_DIGEST_LENGTH;i++){ | |
printf("%02x", hash[i]); | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment