Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created October 26, 2016 16:05
Show Gist options
  • Save AndyNovo/b29fc6c47cc8062ed47945e7d068d649 to your computer and use it in GitHub Desktop.
Save AndyNovo/b29fc6c47cc8062ed47945e7d068d649 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <gcrypt.h>
int main () {
size_t index;
size_t txtLength = 4;
char * hashBuffer = malloc(33);
char * textBuffer = malloc(txtLength+1);
memset(hashBuffer, 0, 33);
strncpy(textBuffer, "andy", txtLength);
gcry_md_hash_buffer(
GCRY_MD_SHA256, // gcry_cipher_hd_t
hashBuffer, // void *
textBuffer, // const void *
txtLength); // size_t
printf("hashBuffer = ");
for (index = 0; index<32; index++)
printf("%02X", (unsigned char)hashBuffer[index]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment