OpenSSL is open source, you can write test code on it, how to write it? Here is an example of this.
The first step: write a test program MD5test1.c, the code is as follows
#include<stdio.h>
#include<openssl/md5.h>
#include<string.h>
int main(int argc,char**argv )
{
MD5_CTX ctx;
unsignedchar*data="123";
unsignedchar md[16];
char buf[33]={'\0'};
char tmp[3]={'\0'};
int i;
MD5_Init(&ctx);
MD5_Update(&ctx,data, strlen (data));
MD5_Final(md,&ctx);
for( i=0; i<16; i++)
{
sprintf (tmp,"%02X",md[i]);
strcat (buf,tmp);
}
printf ("%s\n",buf);
return0;
}
Step 2: Put the code in the following directory:
/openssl-1.1.0c/test
Step 3: Compile
MD5test1.c.
[root@localhost test]# gcc -o MD5test1 MD5test1.c
/tmp/cczP8S6Z.o: In function `main':
MD5test1.c:(.text+0x6b): undefined reference to `MD5_Init'
MD5test1.c:(.text+0x8d): undefined reference to `MD5_Update'
MD5test1.c:(.text+0xa0): undefined reference to `MD5_Final'
collect2: error: ld returned 1 exit status
Three errors occurred.
The reason for the error is
The library containing the md5 function is /usr/lib/libcrypto.a(.so), use -lcrypto when compiling.
Step 4: Recompile
MD5test1.c.
[root@localhost test]# gcc -o MD5test1 MD5test1.c
-lcrypto
Compilation succeeded.
Step 5: Run
MD5test1
[root@localhost test]# ./MD5test1
202CB962AC59075B964B07152D234B70