nt dms_decrypt(char *psz_dest, char *psz_src)
{
//size_t length;
//SEC_UINT32 ilength;
SEC_UCHAR buffer[64];
//SEC_UCHAR src[1024];
SEC_UCHAR pucCipherText[1024];
SEC_UCHAR pucKey[] = PUC_KEY;
SEC_UINT32 algid;
SEC_UINT32 pulCLen;
int i_pwd_length;
int i_len_1st;
int i_len_2nd;
i_len_1st = 0;
i_len_2nd = 0;
memset(buffer, 0x0, sizeof(buffer));
memset(pucCipherText, 0x0, sizeof(pucCipherText));
algid = ALGID_AES128_ECB;
pulCLen = 0;
CRYPT_SET_PAD_MODE(algid,BLOCK_PADDING_NONE);
//base64解码
int len_base64_dec;
len_base64_dec = 0;
if (0 != base64_decode(buffer, psz_src, &len_base64_dec))
{
return -1;
}
//AES解密
if (SEC_SUCCESS != CRYPT_decrypt(algid, pucKey, 16, NULL, 0, buffer, 16, pucCipherText, &pulCLen) )
{
return -1;
}
pucCipherText[pulCLen]='\0';
i_len_1st = pucCipherText[strlen((const char*)pucCipherText) - 2] - 48; //48为ascii码和数字之间差值
i_len_2nd = pucCipherText[strlen((const char*)pucCipherText) - 1] - 48; //48为ascii码和数字之间差值
i_pwd_length = i_len_1st * 10 + i_len_2nd;
if (i_len_1st < 0 || i_len_1st > 9) //6-最小密码长度,8-最大密码长度
{
i_len_1st = 0;
}
if (i_pwd_length < 6 || i_pwd_length > 25) //6-最小密码长度,25-最大密码长度
{
return -1;
}
strncpy(psz_dest, (const char*)pucCipherText, i_pwd_length);
return 0;
}
阅读(1030) | 评论(0) | 转发(0) |