Skip to content

Instantly share code, notes, and snippets.

@frank9615
Created December 10, 2018 18:11
Show Gist options
  • Save frank9615/c28d3f396801db2352ca66b7c88c6137 to your computer and use it in GitHub Desktop.
Save frank9615/c28d3f396801db2352ca66b7c88c6137 to your computer and use it in GitHub Desktop.
/*
* 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