Hello,
I'm trying to use libgcrypt to generate a hash. I'm pretty new to
programming so I'm just testing out the library.
This is the code I've written:
#include <stdio.h>
#include <stdlib.h>
#include <gcrypt.h>
#include <stdbool.h>
int main(void)
{
const char* gcrypt_version = gcry_check_version(NULL);
if (!gcrypt_version)
{
fprintf(stderr, "ERROR: libgcrypt was unable to initialize\n");
exit(2);
}
printf("Gcrypt Version: %s\n", gcrypt_version);
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P))
{
fprintf(stderr, "ERROR: libgcrypt has not been initialized\n");
abort();
}
char* text = "hello\n";
char hash_storage[200] = {0};
gcry_md_hash_buffer(GCRY_MD_MD5, hash_storage, text, strlen(text));
printf("%s\n", hash_storage);
return 0;
}
As you can see I'm just trying to test out this function. Everything
runs but at the end the printf prints out jibberish which I'm unable to
interpret. How is the hash digest encoded?
Yours faithfully,
megamind6155.
I'm trying to use libgcrypt to generate a hash. I'm pretty new to
programming so I'm just testing out the library.
This is the code I've written:
#include <stdio.h>
#include <stdlib.h>
#include <gcrypt.h>
#include <stdbool.h>
int main(void)
{
const char* gcrypt_version = gcry_check_version(NULL);
if (!gcrypt_version)
{
fprintf(stderr, "ERROR: libgcrypt was unable to initialize\n");
exit(2);
}
printf("Gcrypt Version: %s\n", gcrypt_version);
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P))
{
fprintf(stderr, "ERROR: libgcrypt has not been initialized\n");
abort();
}
char* text = "hello\n";
char hash_storage[200] = {0};
gcry_md_hash_buffer(GCRY_MD_MD5, hash_storage, text, strlen(text));
printf("%s\n", hash_storage);
return 0;
}
As you can see I'm just trying to test out this function. Everything
runs but at the end the printf prints out jibberish which I'm unable to
interpret. How is the hash digest encoded?
Yours faithfully,
megamind6155.