Data encryption using the MD5 of the OpenSSL library in a Linux environment

Source: Internet
Author: User
Tags md5 encryption openssl openssl library

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.