I've been working on cryptography implementations in C. I am required to use hash a message using any one of the popular hash functions like SHA,MD5, etc.
In Java, there is a security library which takes care of these things.
But how do I do the same in C?
for example: char *str = "this is a message"; char *hash = SHA(str);
Something of this sort. It would be of great help if some one can point me to some library which has already implemented these functions which i can call for my program.
Thanks!
sphlib is an opensource library which provides optimized (but portable) implementations in C of many hash functions.
OpenSSL is a more generic cryptographic library, which is widely deployed and provides implementations of hash functions, too (less hash functions than sphlib, but it also includes other cryptographic primitives).
OpenSSL is indeed widely available. For your example you could use
unsigned char digest[SHA_DIGEST_LENGTH];
char *str = "this is a string";
SHA1(str, strlen(str), digest);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With