how to print calculated sha1 mac?
Sylvain BERTRAND
sylvain at 2001-space-odyssey.net
Mon Feb 7 15:58:25 CET 2005
Hi,
I've discovered today the great thing that is libgcrypt.
I'm having troubles with displaying the calculated hash though. Below is
the very simple program I wrote to calculate (and print) the SHA1 hash
from a given file.
Is this program correct? What can I do to make the hash printable to a
file or to stdout?
Thank for your help.
Regards,
Sylvain BERTRAND
/* sha1-hash.c */
#include <gcrypt.h>
#include <stdlib.h>
#include <stdio.h>
#define HASH_TYPE GCRY_MD_SHA1
int main (int argc, char ** argv) {
char * filename = argv[1];
int c;
unsigned char *hash;
gcry_md_hd_t h;
gcry_md_open(&h,HASH_TYPE,0);
FILE * file = fopen(filename,"r");
do {
c = fgetc(file);
gcry_md_putc(h,c);
} while (c != EOF);
gcry_md_final(h);
hash = gcry_md_read(h,HASH_TYPE);
fclose(file);
gcry_md_close(h);
/* how to print? */
return 1;
}
More information about the Gnupg-devel
mailing list