I want to find md5sum of a file in Linux C, Is there any API where I can send file name to get md5sum of that file.
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- facebook error invalid key hash for some devices
- glDrawElements only draws half a quad
If you're looking to generate MD5 hash for a file and compare it with a string, you can use this.
Here, I have used D'Nabre's code from another SO answer and Michael Foukarakis's hex string to byte array code from this SO answer. It needs to be linked against the OpenSSL library (gcc md5.c -o md5 -lssl) to work.
Sample usage:
md5.h:
md5.c:
There's code here.
Also, the openssl libs have md5 functions (from here):
An easy answer to the question asked by Raja and using answer from sje397, the md5sum of a file can be calculated within the C program as below. Also notice that there is no need of writing the read command twice when you can use the do while loop.
You can use the mhash library (license is LGPL). On Debian systems:
See the man page
man 3 mhash
But I don't think you can just give it the name of a file. You have to open the file yourself, read the data, and feed the data to this library's functions.
You can use
popen
to runmd5sum
and read the output: