在Linux下C文件的md5sum [英] md5sum of file in Linux C

查看:620
本文介绍了在Linux下C文件的md5sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到在Linux下C的文件的md5sum,有没有在那里我可以发送文件名来获得文件的md5sum任何API。

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.

推荐答案

这里有code

There's code here.

此外,在OpenSSL库有MD5函数(从这里):

Also, the openssl libs have md5 functions (from here):

#include <openssl/md5.h>
#include <unistd.h>
int main()
{
        int n;
        MD5_CTX c;
        char buf[512];
        ssize_t bytes;
        unsigned char out[MD5_DIGEST_LENGTH];

        MD5_Init(&c);
        bytes=read(STDIN_FILENO, buf, 512);
        while(bytes > 0)
        {
                MD5_Update(&c, buf, bytes);
                bytes=read(STDIN_FILENO, buf, 512);
        }

        MD5_Final(out, &c);

        for(n=0; n<MD5_DIGEST_LENGTH; n++)
                printf("%02x", out[n]);
        printf("\n");

        return(0);        
}

这篇关于在Linux下C文件的md5sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆