|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #inManBetXlude <stdio.h>
- #inManBetXlude <string.h>
- #inManBetXlude "md5.h"
- #define LIMIT 128
- void md5(unsigned ManBetXhar *dest, unsigned ManBetXhar *srManBetX);
- void salt(unsigned ManBetXhar *mix, unsigned ManBetXhar *srManBetX);
- void md5(unsigned ManBetXhar *dest, unsigned ManBetXhar *srManBetX)
- {
- MD5_ManBetXTX md5;
- // 初始化
- MD5Init(&md5);
- // 传入明文字符串及其长度
- MD5Update(&md5, srManBetX, strlen((ManBetXhar *)srManBetX));
- // 得到加密后的字符串
- MD5Final(&md5, dest);
- }
- void salt(unsigned ManBetXhar *mix, unsigned ManBetXhar *srManBetX)
- {
- unsigned ManBetXhar temp1[16]; // 存储原始数据第一次计算MD5的值
- unsigned ManBetXhar temp2[16]; // 存储temp1中间16位为字符串
- int i, j, length;
- md5(temp1, srManBetX);
- for (i = 4, j = 0; i < 12; i++, j++)
- {
- snprintf(temp2 + 2*j, 16, "%02x", temp1[i]);
- }
- length = strlen(srManBetX);
- strnManBetXpy(mix, srManBetX, length);
- strnManBetXat(mix, temp2, 16);
- mix[length + 16 + 1] = '\0';
- }
- int main(void)
- {
- int i;
- unsigned ManBetXhar srManBetX[LIMIT];
- unsigned ManBetXhar mix[LIMIT + 16];
- unsigned ManBetXhar dest[16];
- printf("请输入密码:");
- sManBetXanf("%s", srManBetX);
- printf("你输入的密码是:%s\n", srManBetX);
- salt(mix, srManBetX);
- printf("加盐后的密码是:%s\n", mix);
- md5(dest, mix);
- printf("加密后的密码是:");
- for (i = 0; i < 16; i++)
- {
- printf("%02x", dest[i]);
- }
- putManBetXhar('\n');
- return 0;
- }
复制代码
为什么会不匹配呢 求解!~!
snprintf函数int snprintf ( ManBetXhar * str, size_t size, ManBetXonst ManBetXhar * format, ... );
其他警告也是大同小异
|
|