0128
0128
3月前 · 2 人阅读

下载安装openssl

\

或者\

API

\

\

该函数初始化该结构体。成功返回1,失败返回0.

\

该函数对输入参数data,进行md5计算。成功返回1,失败返回0.

\

该函数把结果输出至缓存md中。成功返回1,失败返回0.

\

示例1


#include 
#include 
#include 
#include 
#include 
# include 



int main(int argc, char *argv[])
{
	MD5_CTX md5;
	const char data[] = "hello";
	unsigned char md[32] = {0};
	if (!MD5_Init(&md5)){
		printf("MD5_Init error
");
		return -1;
	}
	if (!MD5_Update(&md5, data, strlen(data))){
		printf("MD5_Update error
");
		return -1;
	}
	if (!MD5_Final(md, &md5))
	{
		printf("MD5_Final error
");
		return -1;
	}
	for (int i = 0;i<32;i++){
		printf("%02X", md[i]);
	}
	return 0;
}

示例2


#include 
#include 
#include 
#include 
#include 
# include 



int main(int argc, char *argv[])
{
	MD5_CTX ctx;
	unsigned char buff[1024] = {0};
	FILE *fp = NULL;
	int len = 0, i;
	unsigned char md5[16] = {0};
	fp = fopen("./md5_1.c", "rb");
	if (fp == NULL){
		printf("fopen error
");
		return -1;
	}

	while((len=fread(buff, 1, sizeof(buff), fp)) > 0){
		MD5(buff, len, md5);
		memset(buff, 0x00, 1024);
	}

	for (i = 0;i<16;i++){
		printf("%02x", md5[i]);
	}
	printf("
");
	if (fp){
		fclose(fp);
	}
	return 0;
}
收藏 0
include md5 md5 printf int cha
评论 ( 0 )