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

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

问题描述

我想在 Linux C 中查找文件的 md5sum,是否有任何 API 可以发送文件名以获取该文件的 md5sum.

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.

推荐答案

代码这里.

此外,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("
");

    return(0);        
}

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

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