C. MD5 encryption source code

Source: Internet
Author: User

From: http://www.fzitshow.com/redirect.php? Tid = 11971 & goto = lastpost

# Include <string. h>
# Include <stdlib. h>
# Include <OpenSSL/md5.h>

// Function prototype;
// Void md5_init (md5_ctx * C );
// Void md5_update (md5_ctx * C, const void * data, unsigned long Len );
// Void md5_final (unsigned char * MD, md5_ctx * C );

Int main (INT argc, char * argv [])
{
Char password [128] = {0 };
Md5_ctx X;
Int I = 0, Len;
Char * out = NULL;
Unsigned char d [16];
Unsigned char TMP [128] = {0 };

If (argc! = 2 ){
Printf ("Usage: % S <message>/N", argv [0]);
Return-1;
}

Strcpy (password, argv [1]);

Md5_init (& X );
Md5_update (& X, (char *) password, strlen (password ));
Md5_final (D, & X );
Out = (char *) malloc (35 );
Memset (Out, 0x00, 35 );
Strcpy (Out, "$1 $ ");
Printf ("MD5 (/" % S/") =", password );
For (I = 0; I <16; I ++ ){
Sprintf (out + (I * 2), "% 02x", d [I]); // convert to 32 bits
}
Out [32] = 0;
Printf ("% s/n", out );

Return 0;
}

// Call libcrypt. So:/usr/lib/libcrypt. So during compilation
Gcc-O MD5 md5.c-lcrypto

// Execute:
./MD5. 123

// Possible result: 202cb962ac59075b964b07152d234b70

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.