Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Created December 3, 2012 20:17
Show Gist options
  • Save Keith-S-Thompson/4197689 to your computer and use it in GitHub Desktop.
Save Keith-S-Thompson/4197689 to your computer and use it in GitHub Desktop.
OpenSSL SHA1 demo

In response to this question:

This works correctly for me on Ubuntu, and produces the same output each time I run it.

Compile with:

gcc c.c -lssl -lcrypto -o c

Run with:

./c

Output:

c9 16 e7 1d 73 3d 06 cb 77 a4 77 5d e5 f7 7f d0 b4 80 a7 e8 
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int main(void)
{
int i;
unsigned char buffer[] = "Whatever"; //input, which is always the same one
unsigned char obuf[20];
SHA1(buffer, strlen(buffer), obuf);
for (i = 0; i < 20; i++) {
printf("%02x ", obuf[i]);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment