the MD5 encryption tool in the OpenSSL library can encrypt the input string and output a 16-byte number. The test code is as follows:
1 //test_md5.c2#include <stdio.h>3#include <string.h>4#include <unistd.h>5#include <openssl/md5.h>6 7 intMd5_test (void*idata, size_t len, unsignedChar*MD5)8 {9 md5_ctx CTX;Ten One if(idata = = NULL | | Len <=0|| MD5 = =NULL) { Aprintf"Input param invalid!\n"); - return-1; - } the -memset (&ctx,0,sizeof(CTX)); -Md5_init (&ctx); -Md5_update (&CTX, Idata, Len); +Md5_final (MD5, &ctx); - + return 0; A } at - voidMd5_test1 (void) - { - Const Char*input_data ="My name is Hancq"; -UnsignedCharmd5[ -]; - inti; in -Md5_test (Input_data, -, MD5); toprintf"Md5_test1:"); + for(i =0; I < -; i++) { -printf"%02x", Md5[i]); the } *printf"\ n"); $ }Panax Notoginseng - voidMd5_test2 (void) the { + Const Char*input_data ="My name is Hancq"; AUnsignedCharmd5[ -]; the inti; + -MD5 (Input_data, -, MD5); $printf"Md5_test2:"); $ for(i =0; I < -; i++) { -printf"%02x", Md5[i]); - } theprintf"\ n"); - }Wuyi the intMainintargcChar**argv) - { Wu Md5_test1 (); - md5_test2 (); About $ return 0; -}
The crypto library needs to be connected at compile time:
gcc test_md5.c-o test-lcrypto
Data encryption results can be verified using the md5sum command under Linux:
Echo " My name is Hancq "
Data encryption using the MD5 of the OpenSSL library in a Linux environment