{"rsdb":{"rid":"156017","subhead":"","postdate":"0","aid":"117123","fid":"49","uid":"1","topic":"1","content":"
\n

\u672c\u6587\u4ecb\u7ecdLinux<\/a> c\u4f7f\u7528openssl\/md5.h\u52a0\u5bc6<\/a>\uff0c\u6709\u4e24\u79cd\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p> \n

\u65b9\u6cd5\u4e00\uff1a<\/p> \n

\r\n#include  \r\n#include  \r\n#include  \r\n  \r\nint main( int argc, char **argv )  \r\n{  \r\n    MD5_CTX ctx;  \r\n    unsigned char *data=\"123\";  \r\n    unsigned char md[16];  \r\n    char buf[33]={'\/0'};  \r\n    char tmp[3]={'\/0'};  \r\n    int i;  \r\n  \r\n    MD5_Init(&ctx);  \r\n    MD5_Update(&ctx,data,strlen(data));  \r\n    MD5_Final(md,&ctx);  \r\n  \r\n    for( i=0; i<16; i++ ){  \r\n        sprintf(tmp,\"%02X\",md[i]);  \r\n        strcat(buf,tmp);  \r\n    }  \r\n    printf(\"%s\/n\",buf);  \r\n    return 0;  \r\n}<\/pre> \n 

\u8f93\u51fa\uff1a<\/p> \n

202CB962AC59075B964B07152D234B70<\/p> \n

\u65b9\u6cd5\u4e8c\uff1a<\/p> \n

\r\n#include  \r\n#include  \r\n#include  \r\n  \r\nint main( int argc, char **argv )  \r\n{  \r\n    unsigned char *data = \"123\";  \r\n    unsigned char md[16];  \r\n    int i;  \r\n    char tmp[3]={'\/0'},buf[33]={'\/0'};  \r\n    MD5(data,strlen(data),md);  \r\n    for (i = 0; i < 16; i++){  \r\n        sprintf(tmp,\"%2.2x\",md[i]);  \r\n        strcat(buf,tmp);  \r\n    }  \r\n    printf(\"%s\/n\",buf);  \r\n    return 0;  \r\n}<\/pre> \n 

\u8f93\u51fa\uff1a<\/p> \n

202cb962ac59075b964b07152d234b70<\/p> \n

\u603b\u7ed3\uff1a<\/p> \n

\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff0c\u4e00\u6837\u7684\u7ed3\u679c\u3002\u76f8\u6bd4\u8f83\uff0c\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u66f4\u76f4\u89c2\u7b80\u5355\u4e9b\u3002<\/p> \n

\u9047\u5230\u7684\u95ee\u9898\uff1a<\/p> \n

1.sprintf\u65f6\u7684\u683c\u5f0f\uff0c%02X\u548c%2.2\u683c\u5f0f\u662f\u4e00\u6837\u7684\uff0c\u5f3a\u5236\u8f93\u51fa\u4e24\u4f4d\uff0c\u6bd4\u5982\u5341\u8fdb\u5236\u76848\uff0c\u5341\u516d\u8fdb\u5236\u4e5f\u662f8\uff0c\u8fd9\u4e2a\u683c\u5f0f\u662f\u63a7\u5236\u8f93\u51fa\u4e24\u4f4d\uff0c08\u3002\u5982\u679c\u52a0\u5bc6\u7ed3\u679c\u8981\u5c0f\u5199\u5b57\u6bcd\u663e\u793a\uff0c\u5c31\u662f\"%2.2x\",\u5927\u5199\u5c31\u662f\"2.2X\"\u3002<\/p> \n

2.\u4e00\u5b9a\u8981\u4f7f\u7528unsigned char,\u867d\u7136\u662fchar\uff0c\u5176\u5b9e\u5c31\u662f\u4e2aint,\u5f53\u7136\uff0c\u5b83\u53ea\u6709\u4e00\u4e2a\u5b57\u8282\uff0c\u548cchar\u7684\u533a\u522b\u662f\uff0cunsigned char 0~255 ,char -127~127\u3002\u4f7f\u7528char\u4f1a\u51fa\u95ee\u9898\u3002\u8fd9\u4e2amd5\u52a0\u5bc6\u51fd\u6570\uff0c\u8fd4\u56de16\u4e2a\u5341\u8fdb\u5236\u6570\uff0c\u8303\u56f4\u57280\uff5e255\u95f4\uff0c\u628a\u5b83format\u4e3a\u5341\u516d\u8fdb\u5236\u5c31\u662f32\u4e3amd5\u7f16\u7801\u4e86\u3002<\/p> \n

3.gcc\u7f16\u8bd1\u7684\u65f6\u5019\uff0c\u540e\u9762\u52a0\u4e0a\u53c2\u6570 -lcrypto \u5982\u679c\u7cfb\u7edf<\/a>\u6ca1\u6709\u5b89\u88c5libcrypto\uff0c\u662f\u4e0d\u80fd\u7528\u8fd9\u4e2a\u65b9\u6cd5\u7684\u3002<\/p> \n

\u5d4c\u5165\u5f0fdebian\u4e0b\u7f16\u8bd1\u60c5\u51b5\uff1a<\/p> \n

1. \u9700\u8981\u5c06char tmp[3]={'\/0'}, buf[33]={'\/0'}; \u66f4\u6539\u4e3achar tmp[3]={}, buf[33]={}; \u5426\u5219gcc\u7f16\u8bd1\u4f1a\u62a5\u9519;<\/p> \n<\/dd>","orderid":"0","title":"linux\u4e0bmd5\u52a0\u5bc6\uff08\u4f7f\u7528openssl\u5e93C\u5b9e\u73b0\uff09","smalltitle":"","mid":"0","fname":"c++\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"131","pages":"1","comments":"0","posttime":"2017-01-10 08:15:00","list":"1484007300","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"linux<\/A> md5<\/A> \u52a0\u5bc6<\/A> \u4f7f\u7528<\/A> openssl<\/A> \u5b9e\u73b0<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.36","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"linux\u4e0bmd5\u52a0\u5bc6\uff08\u4f7f\u7528openssl\u5e93C\u5b9e\u73b0\uff09","lastview":"1500211288","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}