Пример #1
0
/*****************************************************************************
 ** Descriptions:	加密发送包
 ** Parameters:    	SDK_8583_ST8583 *pstSendBag 发送包
 ** Returned value:
 ** Created By:		lilin2012.12.22
 ** Remarks:
 *****************************************************************************/
s32 EncryptSendData(struct _TradeData *pstTradeData,
		SDK_8583_ST8583 *pstSendBag) {
	s32 slt = SDK_OK;
	u8 ucMacBuf[32] = { 0 };
//lilin 20140319
//    //重新改写报文头
//    ReConfigBag8583(pstSendBag);
	//磁道信息加密
	if (pstSendBag == NULL || pstTradeData == NULL) {
		return 0;
	}
	slt = EncryptMagData(pstTradeData, pstSendBag);
	Log("wangb", "EncryptMagData is %d ", slt);
	if (slt != SDK_OK) {
		return SDK_ESC;
	}

	//获得MAC
	if (sdk8583IsDomainExist(pstSendBag, 64)) {
		slt = GetMacData(pstTradeData, pstSendBag, ucMacBuf);
		if (slt != SDK_OK) {
			return SDK_ESC;
		}
		slt = SetFieldData(pstSendBag, 64, ucMacBuf, 8);
		//   slt = SetFieldData(pstSendBag, 64, "\x02\x00\x30\x20\x04\xC0\x20\xC0", 8);
		//    slt = SetFieldData(pstSendBag, 64, "\x32\x42\x35\x39\x36\x33\x39\x37", 8);
		if (slt <= 0) {
			return SDK_ESC;
		}
	}
	return SDK_OK;
}
Пример #2
0
BOOL CBCGPODBCGridCtrl::OnAddData (CBCGPGridRow* pRow, 
								   int nColumn, int nRow)
{
	ASSERT_VALID (pRow);
	ASSERT_VALID (m_pRecordSet);
	ASSERT (!m_pRecordSet->IsEOF ());
	ASSERT (!m_pRecordSet->IsBOF ());

	CDBVariant varValue;
	m_pRecordSet->GetFieldValue ((short) nColumn, varValue);

	return SetFieldData (varValue, pRow, nColumn, nRow);
}
Пример #3
0
/*****************************************************************************
** Descriptions:	组定位报文
** Parameters:          struct _TradeData *pstSaleData
                               u8 *pheSendData
** Returned value:
** Created By:		lilin2012.08.01
** Remarks:
*****************************************************************************/
s32 FormLocationBag(SDK_8583_ST8583 *pstSendBag8583)
{
	u8 ucTradeId;//消息ID
	u8 buf[64] = {0};
	int nRet;
	s32 len = 0,i=0;
	u16 length = 0;

	s32 tmplen = 0;
	u8 temp[256] = {0};
	u8 str[256] = {0};
	u8 aucTempData[256] = { 0 };	// 暂存数据

	struct _KeySystemParam *pst_KeySystemParam = &gstAppSetting.stKeySystemParam;
	struct _SYS *pst_SYS = &gstSys;
	struct _TradeData *pstTradeData = &gstTradeData;

	ucTradeId = pstTradeData->ucTradeId;

    if (pstSendBag8583 == NULL || pstTradeData == NULL)
    {
        return false;
    }
     nRet = FormPublicSend(pstSendBag8583,pstTradeData, "0020000000C00052");
     if(nRet <= 0)
        return nRet;
     SetFieldData(pstSendBag8583, SDK_8583_FIELD_MSG, "0800", 4);

    //58域 定位
	memset(str, 0, sizeof(str));
	length = 0;
	memset(temp, 0, sizeof(temp));
	if ((len = ProviderGetTagValue(TAG_JINGDU, temp)) > 0) {
	memcpy(str, "GA", 2);
	Log("zbq","11111");
	length = length + 2;
	sprintf(str+length,"%03d", len);
	Log("zbq","22222");
	length = length + 3;
	memcpy(str+length, temp, len);
	Log("zbq","33333");
	length = length + len;
	} else {
	return SDK_ERR;
	}
	memset(temp, 0, sizeof(temp));
	if ((len = ProviderGetTagValue(TAG_WEIDU, temp)) > 0) {
	memcpy(str+length, "GB", 2);
	Log("zbq","44444");
	length = length + 2;
	sprintf(str+length,"%03d", len);
	Log("zbq","55555");
	length = length + 3;
	memcpy(str+length, temp, len);
	Log("zbq","666666");
	length = length + len;
	} else {
	return SDK_ERR;
	}
	memset(temp,0,256);
	sdkBcdToAsc(temp,str,length);
	Log("zbq","58域 =  %s ", temp);
	SetFieldData(pstSendBag8583, 58, str, length);

     //60域
    {
//        Log("wangb","pstTradeData->stSysParam.asBatchNo is %s ",pstTradeData->stSysParam.asBatchNo);
        memset(temp, 0, sizeof(temp));
        strcat(temp, "00");  //60.1
        strcat(temp,gstSys.asBatchNo);   //60.2批次号

        //60.3网络管理信息码
        strcat(temp, "998");
        SetFieldData(pstSendBag8583, 60, temp, strlen(temp));
    }

    //63域
	memset(temp, 0, sizeof(temp));
	sprintf(temp, "%03d", gstTradeData.usManNo);
	i = strlen(temp);
//	if (i < 3)
//	{
//		temp[2] = 0x20;
//	}

	/*=======BEGIN: huangxin 2015.01.25  13:7 modify===========
            在密钥下载交易中,上送终端型号(厂商名|型号)。
            该域由两个子域构成,具体描述如下:
            63.2.1   保留域   固定值"  "
            63.2.2   终端型号信息  ANS20
            命名规范
            厂商缩写+"|"+产品型号,总长度不超过20位,其中字符要求为英文
            和数字,不予许其他字符,以竖线分割。
            例如:00LANDI |EPT5630
	============================== END======================== */
	memcpy(temp+i, " XGD|", 5);
	i += 5;
//        rlt = sdkSysGetMachineCode(NULL);
//        ConverMachineCode(rlt, &temp[i]);
	memcpy(temp+i, "G870 ", 5);
	Log("zbq","63 Filed = %s",temp);
	SetFieldData(pstSendBag8583, 63, temp, strlen(temp));

	//重新改写报文头
	ReConfigBag8583(pstSendBag8583);

#ifdef EncriptBagControl
	nRet = WriteSendBag(TAG_8583_SENDBAG,pstSendBag8583);
	//全报文加密
	EncryptAllMsgByHX(1, pstSendBag8583->ucBagData, &pstSendBag8583->nBagLen);
#endif

	return pstSendBag8583->nBagLen;
}
Пример #4
0
/*****************************************************************************
 函 数 名  : EncryptMagData
 功能描述  : 磁道数据加密
 输入参数  : u8 *pheDataBuf
 s32 *iDataLen
 输出参数  : 无
 返 回 值  :
 调用函数  :
 被调函数  :

 修改历史      :
 1.日    期   : 2012年12月26日
 作    者   : wuzhonglin
 修改内容   : 新生成函数

 *****************************************************************************/
s32 EncryptMagData(struct _TradeData *pstTradeData, SDK_8583_ST8583 *pstSendBag) {
	u8 tmp[256], buf[128], outbuf[128] = { 0 };
	s32 iLen, pOutLen;
	s32 slt = SDK_OK;
	u8 *pBuf;
	bool bIsEncryp = false;
// && pstTradeData->stKeySystemParam.bIsMk3Des
//    iLen = GetFieldData(pstSendBag, 35, tmp, sizeof(tmp));
//    && pstTradeData->stKeySystemParam.bIsMk3Des
	if (gstAppSetting.stKeySystemParam.bIsSupportTdk
			&& (sdk8583IsDomainExist(pstSendBag, 35)
					|| sdk8583IsDomainExist(pstSendBag, 36))) {
		memset(tmp, 0, sizeof(tmp));
		iLen = GetFieldData(pstSendBag, 35, tmp, sizeof(tmp));
		Log("wangb", "Field35_1=%s", tmp);
		if (iLen > 16) {
//            sdkAscToBcd(buf, tmp, iLen);
//            pBuf = &buf[(iLen + 1) / 2 - 9];
			//加密

			//   slt = sdkPEDWkDes(pstTradeData->stKeySystemParam.uiTdkIndex, SDK_PED_DES_TRIPLE, SDK_PED_ENCRYPT, pBuf, pBuf);
			slt = ProviderTrackDataEncrypt(tmp, outbuf, &pOutLen);   //Fixme
			if (slt != SDK_OK) {
				return SDK_ERR;
			}
//          sdkBcdToAsc(tmp, outbuf, (pOutLen + 1) / 2);
			sdkBcdToAsc(tmp, outbuf, pOutLen);
			Log("wangb", "Field35_2 %s", tmp);
			sdk8583ClrField(pstSendBag, 35);
			SetFieldData(pstSendBag, 35, tmp, iLen);

			bIsEncryp = true;
		}
		memset(tmp, 0, sizeof(tmp));
		memset(outbuf, 0, sizeof(outbuf));
		iLen = GetFieldData(pstSendBag, 36, tmp, sizeof(tmp));
		if (iLen > 16) {
//
//            sdkAscToBcd(buf, tmp, iLen);
//            pBuf = &buf[(iLen + 1) / 2 - 9];
			//加密
//            slt = sdkPEDWkDes(pstTradeData->stKeySystemParam.uiTdkIndex, SDK_PED_DES_TRIPLE, SDK_PED_ENCRYPT, pBuf, pBuf);
			slt = ProviderTrackDataEncrypt(tmp, outbuf, &pOutLen);
			if (slt != SDK_OK) {
				return SDK_ERR;
			}
//          sdkBcdToAsc(tmp, buf, (iLen + 1) / 2);
			sdkBcdToAsc(tmp, outbuf, pOutLen);
			sdk8583ClrField(pstSendBag, 36);
			SetFieldData(pstSendBag, 36, tmp, iLen);
			bIsEncryp = true;
		}
	}
	if (bIsEncryp) {
		//重新设置53域TRACK-ENCRYPTION-USED
		iLen = 0;
		memset(tmp, 0, sizeof(tmp));
		iLen = GetFieldData(pstSendBag, 53, tmp, sizeof(tmp));
		if (iLen >= 3) {
			tmp[2] = '1';
			sdk8583ClrField(pstSendBag, 53);
			SetFieldData(pstSendBag, 53, tmp, iLen);
		} else {
			strcpy(tmp, "001");
			if (gstAppSetting.stKeySystemParam.bIsMk3Des)        // 3des
			{
				tmp[1] = '6';
			}
			SetFieldData(pstSendBag, 53, tmp, strlen(tmp));
		}
	}
	Log("wangb", "pucMacBuf3 is %s", tmp);
	return SDK_OK;
}