반응형
#include <stdio.h>
#include <openssl/sha.h>
#include <string.h>
int main()
{
// The input message
const char *message = "Hello, OpenSSL SHA-256!";
// Buffer to hold the SHA256 digest
unsigned char hash[SHA256_DIGEST_LENGTH];
// Compute the SHA-256 hash
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, message, strlen(message));
SHA256_Final(hash, &sha256);
// Print the hash as hexadecimal
printf("SHA-256 hash: ");
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
printf("%02x", hash[i]);
}
printf("\n");
return 0;
}
컴파일
gcc -o sha256_example sha256_example.c -lssl -lcrypto
반응형