全部!
我正在尝试从 mifare 卡 1k 读取数据。
获取
我发送的 ID:0xFF 0xCA 0x00 0x00 0x00
接收:0x00 0x00 0x00 0x00 0x00 0x00 - ??? 这是正常的?
将身份验证密钥加载到阅读器
我发送:0xFF 0x82 0x00 0x00 0x06 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
接收:90 00 - 没关系
在块 01 中进行身份验证
我发送:0xFF 0x86 0x00 0x00 0x05 0x01 0x00 0x01 0x60 0x00
接收:90 00 - 没关系
从块 01 读取数据
我发送:0xFF 0xB0 0x00 0x01 0x0F
接收:63 00 - 如何理解它的身份验证错误
我不明白——为什么?
我的代码:
#include "stdafx.h"
#include "Winscard.h"
LPTSTR pmszReaders = NULL;
LPTSTR pmszCards = NULL;
LPTSTR pReader;
LPTSTR pCard;
LONG lReturn, lReturn2;
DWORD cch = SCARD_AUTOALLOCATE;
SCARDCONTEXT hSC;
SCARD_READERSTATE readerState;
LPCTSTR readerName = L"ACS ACR1222 1S Dual Reader 0";
SCARDHANDLE hCardHandle;
DWORD dwAP;
BYTE pbRecv[50];
DWORD dwRecv;
BYTE cmdGetData[] = {0xFF, 0xCA, 0x00, 0x00, 0x00};
BYTE cmdLoadKey[] = {0xFF, 0x82, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
BYTE cmdAuthBlock01[] = {0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 0x01, 0x60, 0x00};
BYTE cmdReadBlock01[] = {0xFF, 0xB0, 0x00, 0x01, 0x0F};
int _tmain(int argc, _TCHAR* argv[]) {
lReturn = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hSC);
if ( SCARD_S_SUCCESS != lReturn )
printf("Failed SCardEstablishContext\n");
else {
lReturn = SCardListReaders(hSC, NULL, (LPTSTR)&pmszReaders, &cch );
if (lReturn != SCARD_S_SUCCESS) {
printf("Failed SCardListReaders\n");
} else {
pReader = pmszReaders;
while ( '\0' != *pReader ) {
printf("Reader: %S\n", pReader );
pReader = pReader + wcslen((wchar_t *)pReader) + 1;
}
}
memset(&readerState,0,sizeof(readerState));
readerState.szReader = pmszReaders;
lReturn = SCardConnect( hSC, pmszReaders, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCardHandle, &dwAP );
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardConnect\n");
system("pause");
exit(1);
} else {
printf("Success SCardConnect\n");
switch ( dwAP ) {
case SCARD_PROTOCOL_T0:
printf("Active protocol T0\n");
break;
case SCARD_PROTOCOL_T1:
printf("Active protocol T1\n");
break;
case SCARD_PROTOCOL_UNDEFINED:
default:
printf("Active protocol unnegotiated or unknown\n");
break;
}
}
lReturn = SCardTransmit(hCardHandle, SCARD_PCI_T1, cmdGetData, sizeof(cmdGetData), NULL, pbRecv, &dwRecv);
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardTransmit\n");
} else {
printf("Success SCardTransmit\n");
printf("Read %u bytes\n", dwRecv);
for(byte i=0;i<dwRecv;i++) {
printf("%x ", pbRecv[i]);
}
printf("\n");
}
lReturn = SCardTransmit(hCardHandle, SCARD_PCI_T1, cmdLoadKey, sizeof(cmdLoadKey), NULL, pbRecv, &dwRecv);
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardTransmit\n");
} else {
printf("Success SCardTransmit\n");
printf("Read %u bytes\n", dwRecv);
for(byte i=0;i<dwRecv;i++) {
printf("%x ", pbRecv[i]);
}
printf("\n");
}
lReturn = SCardTransmit(hCardHandle, SCARD_PCI_T1, cmdAuthBlock01, sizeof(cmdAuthBlock01), NULL, pbRecv, &dwRecv);
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardTransmit\n");
} else {
printf("Success SCardTransmit\n");
printf("Read %u bytes\n", dwRecv);
for(byte i=0;i<dwRecv;i++) {
printf("%x ", pbRecv[i]);
}
printf("\n");
}
lReturn = SCardTransmit(hCardHandle, SCARD_PCI_T1, cmdReadBlock01, sizeof(cmdReadBlock01), NULL, pbRecv, &dwRecv);
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardTransmit\n");
} else {
printf("Success SCardTransmit\n");
printf("Read %u bytes\n", dwRecv);
for(byte i=0;i<dwRecv;i++) {
printf("%x ", pbRecv[i]);
}
printf("\n");
}
}
lReturn = SCardDisconnect(hCardHandle, SCARD_LEAVE_CARD);
if ( SCARD_S_SUCCESS != lReturn ) {
printf("Failed SCardDisconnect\n");
} else {
printf("Success SCardDisconnect\n");
}
system("pause");
return 0;
}
谁能解释我为什么得到 63 00?谢谢。