Created
December 8, 2011 12:28
-
-
Save tmiz/1446849 to your computer and use it in GitHub Desktop.
a sample which using openssl
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
#include <stdio.h> | |
#include <string.h> | |
#include "openssl/opensslv.h" | |
#include "openssl/sha.h" | |
void printBufferOfSha256(const unsigned char *output) | |
{ | |
int i = 0; | |
for(; i < SHA256_DIGEST_LENGTH; i++) { | |
printf("%02x", output[i]); | |
} | |
printf("\n"); | |
} | |
void sha256(char *input, size_t inSize, unsigned char hash[SHA256_DIGEST_LENGTH]) | |
{ | |
SHA256_CTX sha256_context; | |
SHA256_Init(&sha256_context); | |
SHA256_Update(&sha256_context, input, inSize); | |
SHA256_Final(hash, &sha256_context); | |
} | |
int main() | |
{ | |
printf("Using %s\n", OPENSSL_VERSION_TEXT); | |
unsigned char hash[SHA256_DIGEST_LENGTH]; | |
const char *message = "hello"; | |
sha256((char *)message, strlen(message), hash); | |
printBufferOfSha256(hash); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment