• 大小: 19KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: 其他
  • 标签: mac  pcsc  pcsclite  xcode  

资源简介

Mac Lion已经内置了pcscd作为智能卡框架,以及向windows靠拢的pcsclite作为开发库,文件为在Mac上实现了智能卡连接的xcode工程。具体描述参见本人csdn博客。

资源截图

代码片段和文件信息

//
//  main.cpp
//  Ululation
//
//  Created by Caesar on 12-9-6.
//  Copyright (c) 2012年 Caesar. All rights reserved.
//

#include 
#include 

int main(int argc const char * argv[])
{

    SCARDCONTEXT    m_hContext;
    SCARDHANDLE     m_hCard;
    
    //Insert
    if(SCARD_S_SUCCESS != SCardEstablishContext(SCARD_SCOPE_USER NULL NULL &m_hContext))
    {
        std::cerr << “Context error“;
        return -1;
    }
    
    //List Reader
    char pmszReaders[100];
    uint32_t cch = 100;
    if(SCARD_S_SUCCESS != SCardListReaders(m_hContext NULL pmszReaders &cch))
    {
        std::cerr << “List Reader error“;
        return -2;
    }
    
    uint32_t i = 0;
        
    std::cout<<“List Reader: “ << std::endl;
    
    while(i        std::cout<        
        i += strlen(pmszReaders);
        i ++;
    }
    
    //Connect first Reader
    SCARD_IO_REQUEST io;
    io.cbPciLength = sizeof(SCARD_IO_REQUEST);
    
    if(SCARD_S_SUCCESS != SCardConnect(m_hContext pmszReaders SCARD_SHARE_SHARED SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1 &m_hCard &io.dwProtocol)) {
        std::cerr << “Connect Card error“;
        return -3;
    }
    
    //Transmit APDU
    unsigned char CAPDU[] = {0x000xA40x040x000x00};
    unsigned char RAPDU[256+2];
    uint32_t RecvLength = 256+2;
    
    if(SCARD_S_SUCCESS != SCardTransmit(m_hCard &io CAPDU 5 NULL RAPDU &RecvLength))
    {
        std::cerr << “Transmit APDU error“;
        return -4;
    }
    
    //echo
    std::cout<<“Transmit APDU: “ << std::endl;
    std::cout << “CAPDU: “;
    for(i=0;i<5;i++)
    {
        char hexbuf[3];
        sprintf(hexbuf “%02X“ CAPDU[i]);
        std::cout << hexbuf;
    }
    std::cout << std::endl;
    
    std::cout << “RAPDU: “;
    for(i=0;i    {
        char hexbuf[3];
        sprintf(hexbuf “%02X“ RAPDU[i]);
        std::cout << hexbuf;
    }
    std::cout << std::endl;
    
    //Disconnect
    SCardDisconnect(m_hCard SCARD_EJECT_CARD);
    
    //Eject
    SCardReleaseContext(m_hContext);
    return 0;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-09-18 16:55  Ululation\
     文件        6148  2012-09-18 18:03  Ululation\.DS_Store
     目录           0  2012-09-20 14:02  __MACOSX\
     目录           0  2012-09-20 14:02  __MACOSX\Ululation\
     文件          82  2012-09-18 18:03  __MACOSX\Ululation\._.DS_Store
     目录           0  2012-09-06 16:58  Ululation\Ululation\
     文件        2129  2012-09-06 16:58  Ululation\Ululation\main.cpp
     目录           0  2012-09-20 14:02  __MACOSX\Ululation\Ululation\
     文件         171  2012-09-06 16:58  __MACOSX\Ululation\Ululation\._main.cpp
     文件        3123  2012-09-06 15:25  Ululation\Ululation\Ululation.1
     文件         171  2012-09-06 15:25  __MACOSX\Ululation\Ululation\._Ululation.1
     目录           0  2012-09-06 16:26  Ululation\Ululation.xcodeproj\
     文件        7126  2012-09-06 16:26  Ululation\Ululation.xcodeproj\project.pbxproj
     目录           0  2012-09-06 15:25  Ululation\Ululation.xcodeproj\project.xcworkspace\
     文件         154  2012-09-06 15:25  Ululation\Ululation.xcodeproj\project.xcworkspace\contents.xcworkspacedata
     目录           0  2012-09-06 15:25  Ululation\Ululation.xcodeproj\project.xcworkspace\xcuserdata\
     目录           0  2012-09-18 18:03  Ululation\Ululation.xcodeproj\project.xcworkspace\xcuserdata\mac.xcuserdatad\
     文件       14957  2012-09-18 18:03  Ululation\Ululation.xcodeproj\project.xcworkspace\xcuserdata\mac.xcuserdatad\UserInterfaceState.xcuserstate
     目录           0  2012-09-06 15:25  Ululation\Ululation.xcodeproj\xcuserdata\
     目录           0  2012-09-06 16:52  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\
     目录           0  2012-09-18 16:55  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\xcdebugger\
     文件         635  2012-09-18 16:55  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\xcdebugger\Breakpoints.xcbkptlist
     目录           0  2012-09-06 15:25  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\xcschemes\
     文件        3143  2012-09-06 15:25  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\xcschemes\Ululation.xcscheme
     文件         481  2012-09-06 15:25  Ululation\Ululation.xcodeproj\xcuserdata\mac.xcuserdatad\xcschemes\xcschememanagement.plist

评论

共有 条评论