能力值:
( LV4,RANK:50 )
|
-
-
2 楼
...这个库自带文档挺好的啊!只是更新不是太及时,貌似作者不太更新了
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
ls知道libtomcrypt库怎末用吗?
|
能力值:
( LV4,RANK:50 )
|
-
-
4 楼
你问的问题太抽象...
//// Keygenerate() START ////
T_u_int len, cnt;
hash_state md5;
T_u_byte MD5Hash[MD5HASHLEN] = {0};
symmetric_key skey;
T_u_byte temp[MAXBUFFERLEN] = {0};
T_u_byte plane[MAXBUFFERLEN] = {0};
T_u_byte cipher[MAXBUFFERLEN] = {0};
//得到输入的用户信息
char *l_pCardPwd = new char[MAXINPUTLEN + 1];
len = SendMessage(_hWndCardPwd, WM_GETTEXT, MAXINPUTLEN + 1, (LPARAM)l_pCardPwd);
if((len < MININPUTLEN) || (len != 8))
{
SendMessage(_hWndUserSerial, WM_SETTEXT, 0, (LPARAM)szError1);
delete [] l_pCardPwd;
return (-1);
}
char *l_pReqCode = new char[MAXINPUTLEN + 1];
len = SendMessage(_hWndReqCode, WM_GETTEXT, MAXINPUTLEN + 1, (LPARAM)l_pReqCode);
if(len < MININPUTLEN)
{
SendMessage(_hWndUserSerial, WM_SETTEXT, 0, (LPARAM)szError2);
delete [] l_pReqCode;
return (-1);
}
//计算输入密码的MD5值
md5_init(&md5);
md5_process(&md5, (T_u_byte *)l_pCardPwd, 8);
md5_done(&md5, MD5Hash);
//由输入的申请码计算加密的信息串
//1.去除输入序列号中的无效字符
if (!InitReqCode(l_pReqCode))
{
SendMessage(_hWndUserSerial, WM_SETTEXT, 0, (LPARAM)szError3);
delete [] l_pReqCode;
return (-1);
}
//2.base32解码
Base32Decode(l_pReqCode, temp);
//3.xor
for (cnt = 0; cnt < 12; cnt++)
{
temp[cnt] ^= XorTable[cnt];
}
memcpy(cipher, temp + 4, 8);
//以MD5的结果(取前8个字节)为密钥解密得到明文信息串
des_setup(MD5Hash, 8, 16, &skey);
des_ecb_decrypt(cipher, plane, &skey);
//重组明文信息串得到序列号明文
memset(temp, 0, MAXBUFFERLEN);
memcpy(temp, plane, 8);
memset(plane, 0, MAXBUFFERLEN);
memset(cipher, 0, MAXBUFFERLEN);
plane[0] = 0x04; //版本信息
plane[4] = 0x00; //用户数目
plane[5] = 0x00;
plane[6] = 0x04;
plane[7] = 0xC8;
//一次一密噪音信息
memcpy(plane + 1, temp + 4, 3);
//以MD5的结果(取前8个字节)为密钥加密序列号明文
des_ecb_encrypt(plane, cipher, &skey);
//xor
for (cnt = 0; cnt < 8; cnt++)
{
cipher[cnt] ^= XorTable[cnt];
}
//base32编码
char *l_pTempSerial = new char[MAXBUFFERLEN];
memset(l_pTempSerial, 0, MAXBUFFERLEN);
Base32Encode(cipher, 8, l_pTempSerial);
//补齐15
lstrcat(l_pTempSerial, "OR");
//格式化输出序列号
char *l_pUserSerial = new char[MAXBUFFERLEN];
memset(l_pUserSerial, 0, MAXBUFFERLEN);
for (cnt = 0; cnt < 21; cnt++)
{
if (((cnt % 8) == 5) || ((cnt % 8) == 7))
{
l_pUserSerial[cnt] = ' ';
}
else if ((cnt % 8) == 6)
{
l_pUserSerial[cnt] = '-';
}
else
{
l_pUserSerial[cnt] = l_pTempSerial[cnt - ((cnt + 1) / 8) * 3];
}
}
//输出序列号
SendMessage(_hWndUserSerial, WM_SETTEXT, 0, (LPARAM)l_pUserSerial);
//清理创建的数据
delete [] l_pCardPwd;
delete [] l_pReqCode;
delete [] l_pTempSerial;
delete [] l_pUserSerial;
return 0;
//// Keygenerate() END ////
这是早年写的一个kg,其中MD5和DES是用libTomCrypt的。问问题请问详细,冲上来问会不会用而不具体说明你如何尝试?遇到什么困难?谁也无法帮助你~~
|