可以在freebsd/macos/linux下编译运行。
gcc -o test test.c -lcrypto
----test.c---
#include <openssl/md5.h>
#include <stdio.h>
int main{
//MD5_CTX md5;
//MD5_Init(&md5);
//unsigned char md[1024] = {0};
//MD5_Update(&md5,mac,strlen(mac));
//MD5_Final(md,&md5);
char mac[100] = {0};
//MD5_Init(&md5);
//unsigned char md[1024] = {0};
//MD5_Update(&md5,mac,strlen(mac));
//MD5_Final(md,&md5);
char mac[100] = {0};
strcpy(mac,"12345678");
char *md;
int l = strlen(mac);
md = (char *)MD5((const unsigned char *)mac,l,NULL);
int len = strlen((char *)md);
char strmd5[1024] = {0};
for(int i=0; i<len; i++){
sprintf(strmd5+strlen(strmd5),"%02X",md[i]&0xFF);
}
//printf("%s/n",strmd5);
int l = strlen(mac);
md = (char *)MD5((const unsigned char *)mac,l,NULL);
int len = strlen((char *)md);
char strmd5[1024] = {0};
for(int i=0; i<len; i++){
sprintf(strmd5+strlen(strmd5),"%02X",md[i]&0xFF);
}
//printf("%s/n",strmd5);
}
本文提供了一个简单的C语言程序示例,演示如何使用OpenSSL库中的MD5函数来计算字符串的MD5哈希值。代码适用于FreeBSD、macOS及Linux等平台,并通过gcc编译。

被折叠的 条评论
为什么被折叠?



