📄 xkeyapiexampledlg.cpp
字号:
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Create PrivateFile
memcpy(pbCommData,"\x00\xe0\x00\x00\x23\x62\x21\x83\x02\x00\x12\x81\x02\x01\x47\x82\x01\x01\x85\x01\x07\xab\x11\x80\x01\x7F\x90\x00\x90\x00\x90\x00\x90\x00\x90\x00\x90\x00\x97\x00",40);
dwRespLen=MAXRESPLEN;
m_list.AddString("Create PrivateFile:");
st=mw_protocol(icdev[g_port],40,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Active PrivateFile
memcpy(pbCommData,"\x00\x44\x02\x00\x02\x00\x12",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Active PrivateFile:");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Create BinaryFile(Update_Auth controled by PIN)
memcpy(pbCommData,"\x00\xe0\x00\x00\x23\x62\x21\x83\x02\x00\x01\x81\x02\x01\x00\x82\x01\x01\xab\x14\x80\x01\x7F\x90\x00\x90\x00\x90\x00\x90\x00\x90\x00\xa4\x03\x83\x01\x81\x90\x00",40);
dwRespLen=MAXRESPLEN;
m_list.AddString("Create BinaryFile:");
st=mw_protocol(icdev[g_port],40,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Active BinaryFile
memcpy(pbCommData,"\x00\x44\x02\x00\x02\x00\x01",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Active BinaryFile:");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Active DF
memcpy(pbCommData,"\x00\x44\x00\x00\x02\xDF\x01",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Active DF:");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Active MF
memcpy(pbCommData,"\x00\x44\x00\x00\x02\x3F\x00",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Active MF:");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
}
void CXKeyAPIExampleDlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
void CXKeyAPIExampleDlg::OnReadwritefile()
{
// TODO: Add your control notification handler code here
m_list.ResetContent();
if(icdev[g_port]==NULL)
{
strPrompt.Format("Please Input Device!");
m_list.AddString(strPrompt);
return;
}
//eKey Reset
dwRespLen=MAXRESPLEN;
st=mw_reset(icdev[g_port],pbRespData,dwRespLen);
if (st!=0)
{
strPrompt.Format("Reset Error: 0x%02x",st);
m_list.AddString(strPrompt);
return ;
}
hex_asc(pbRespData,(UCHAR*)szTempStr,dwRespLen);
strPrompt.Format("Reset ATR: %s",szTempStr);
m_list.AddString(strPrompt);
m_list.AddString("");
//Select DF(DF01)
memcpy(pbCommData,"\x00\xa4\x08\x00\x02\xDF\x01",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Select DF(DF01):");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
/////////////////////////////////////Read/Write BinaryFile////////////////////////////////
//Select File(0001)
memcpy(pbCommData,"\x00\xa4\x02\x00\x02\x00\x01",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Select BinaryFile:");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Verify Pin
memcpy(pbCommData,"\x00\x20\x00\x81\x04\x31\x32\x33\x34",9);
dwRespLen=MAXRESPLEN;
m_list.AddString("Verify Pin:");
st=mw_protocol(icdev[g_port],9,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Write BinaryFile
memcpy(pbCommData,"\x00\xd6\x00\x00\x14\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30",25);
dwRespLen=MAXRESPLEN;
m_list.AddString("Write BinaryFile:");
st=mw_protocol(icdev[g_port],25,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
//Read BinaryFile
memcpy(pbCommData,"\x00\xb0\x00\x00\x14",5);
dwRespLen=MAXRESPLEN;
m_list.AddString("Read BinaryFile:");
st=mw_protocol(icdev[g_port],5,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
m_list.AddString("Read/Write Compare:");
st=(__int16)memcmp(pbRespData,"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30",20);
if (st!=0)
{
strPrompt.Format("Read/Write Compare Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
m_list.AddString("");
}
void CXKeyAPIExampleDlg::OnRsageneratekeypair()
{
// TODO: Add your control notification handler code here
DWORD dwStart, dwStop ;
m_list.ResetContent();
if(icdev[g_port]==NULL)
{
strPrompt.Format("Please Input Device!");
m_list.AddString(strPrompt);
return;
}
//eKey Reset
dwRespLen=MAXRESPLEN;
st=mw_reset(icdev[g_port],pbRespData,dwRespLen);
if (st!=0)
{
strPrompt.Format("Reset Error: 0x%02x",st);
m_list.AddString(strPrompt);
return ;
}
hex_asc(pbRespData,(UCHAR*)szTempStr,dwRespLen);
strPrompt.Format("Reset ATR: %s",szTempStr);
m_list.AddString(strPrompt);
m_list.AddString("");
//Select DF(DF01)
memcpy(pbCommData,"\x00\xa4\x08\x00\x02\xDF\x01",7);
dwRespLen=MAXRESPLEN;
m_list.AddString("Select DF(DF01):");
st=mw_protocol(icdev[g_port],7,pbCommData,dwRespLen,pbRespData);
if (st!=0)
{
strPrompt.Format("Transfer Error: %d",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %02x%02x",pbRespData[dwRespLen-2],pbRespData[dwRespLen-2+1]);
m_list.AddString(strPrompt);
m_list.AddString("");
/////////////////////////////////////GenerateKeyPair////////////////////////////////
//Initial
m_list.AddString("XInitRSAGenerateKeyPair:");
st=XInitRSAGenerateKeyPair(icdev[g_port]);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
m_list.AddString("");
//GenerateKeyPair
m_list.AddString("XRSAGenerateKeyPair:");
dwStart = GetTickCount();
st=XRSAGenerateKeyPair(icdev[g_port],0xC0,0x0012,0x0011);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
dwStop = GetTickCount() ;
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
strPrompt.Format("Generate Time: %dms ",dwStop-dwStart);
m_list.AddString(strPrompt);
m_list.AddString("");
}
void CXKeyAPIExampleDlg::OnSignverify()
{
// TODO: Add your control notification handler code here
DWORD dwStart, dwStop ;
UCHAR pbToSignData[MAXDATALEN],pbSignValue[MAXDATALEN];
DWORD lSignValueLen,lResumeLen;
UCHAR pbResumeValue[MAXDATALEN];
m_list.ResetContent();
if(icdev[g_port]==NULL)
{
strPrompt.Format("Please Input Device!");
m_list.AddString(strPrompt);
return;
}
//eKey Reset
dwRespLen=MAXRESPLEN;
st=mw_reset(icdev[g_port],pbRespData,dwRespLen);
if (st!=0)
{
strPrompt.Format("Reset Error: 0x%02x",st);
m_list.AddString(strPrompt);
return ;
}
hex_asc(pbRespData,(UCHAR*)szTempStr,dwRespLen);
strPrompt.Format("Reset ATR: %s",szTempStr);
m_list.AddString(strPrompt);
m_list.AddString("");
/////////////////////////////////////Sign/Verify////////////////////////////////
//Sign Initial
m_list.AddString("XInitRSASign:");
st=XInitRSASign(icdev[g_port],RESUME_SIGN_MODE,0xC0,"DF010012",0,NULL);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
m_list.AddString("");
//Sign
m_list.AddString("XRSASign:");
memset(pbToSignData,0x00,0x80);
memcpy(&pbToSignData[0x80-20],"\x11\x22\x33\x44\x55\x66\x77\x88\x99\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\x00",20);
dwStart = GetTickCount();
st=XRSASign(icdev[g_port],RESUME_SIGN_MODE,0x80,pbToSignData,&lSignValueLen,pbSignValue);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
dwStop = GetTickCount() ;
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
strPrompt.Format("Sign Time: %dms ",dwStop-dwStart);
m_list.AddString(strPrompt);
m_list.AddString("");
//Verify Initial
m_list.AddString("XInitRSAVerify:");
st=XInitRSAVerify(icdev[g_port],RESUME_SIGN_MODE,0xc0,"DF010011",0,NULL);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
m_list.AddString("");
//Verify
m_list.AddString("XRSAVerify:");
dwStart = GetTickCount();
st=XRSAVerify(icdev[g_port],RESUME_SIGN_MODE,lSignValueLen,pbSignValue,0,NULL,&lResumeLen,pbResumeValue);
if (st!=0)
{
strPrompt.Format("Error: %04x",st);
m_list.AddString(strPrompt);
return ;
}
dwStop = GetTickCount() ;
st=memcmp(pbToSignData,pbResumeValue,lResumeLen);
if (st!=0)
{
strPrompt.Format("Compare Error!");
m_list.AddString(strPrompt);
return ;
}
strPrompt.Format("Return: %d",st);
m_list.AddString(strPrompt);
strPrompt.Format("Verify Time: %dms ",dwStop-dwStart);
m_list.AddString(strPrompt);
m_list.AddString("");
}
void CXKeyAPIExampleDlg::OnReset()
{
// TODO: Add your control notification handler code here
m_list.ResetContent();
if(icdev[g_port]==NULL)
{
strPrompt.Format("Please Input Device!");
m_list.AddString(strPrompt);
return;
}
//eKey Reset
dwRespLen=MAXRESPLEN;
st=mw_reset(icdev[g_port],pbRespData,dwRespLen);
if (st!=0)
{
strPrompt.Format("Reset Error: 0x%02x",st);
m_list.AddString(strPrompt);
return ;
}
hex_asc(pbRespData,(UCHAR*)szTempStr,dwRespLen);
strPrompt.Format("Reset ATR: %s",szTempStr);
m_list.AddString(strPrompt);
m_list.AddString("");
}
BOOL CXKeyAPIExampleDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if(icdev[g_port]!=NULL)
mw_close(icdev[g_port]);
return CDialog::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -