• C#.net Smart Card PC/SC using WinSCard.Dll


    最近做的一個案子要讀取健保卡的公開資料,可以讀取身分證字號、姓名、生日等資訊,發現非常好用,可以應用在一些需要大量填寫個人資料的地方,例如申請會員等,可改用讀取IC卡,就不需要填一堆資料,又因為健保IC卡的安全機制,所以不會有醫療資料外洩的疑慮。查了很多資料,以下是比較重要的部分指令:

    首先將可能會用到的WinScard指令先Import進來:

            [DllImport("WinScard.dll")]

            public static extern int SCardEstablishContext(uint dwScope, int nNotUsed1,

            int nNotUsed2, ref int phContext);

            [DllImport("WinScard.dll")]

            public static extern int SCardReleaseContext(int phContext);

            [DllImport("WinScard.dll")]

            public static extern int SCardConnect(int hContext, string cReaderName,

            uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref int ActiveProtocol);

            [DllImport("WinScard.dll")]

            public static extern int SCardDisconnect(int hCard, int Disposition);

            [DllImport("WinScard.dll")]

            public static extern int SCardListReaderGroups(int hContext, ref string cGroups, ref int nStringSize);

            [DllImport("WinScard.dll")]

            public static extern int SCardListReaders(int hContext, string cGroups,

            ref string cReaderLists, ref int nReaderCount);

            [DllImport("WinScard.dll")]

            public static extern int SCardFreeMemory(int hContext, string cResourceToFree);

            [DllImport("WinScard.dll")]

            public static extern int SCardGetAttrib(int hContext, uint dwAttrId,

            ref byte[] bytRecvAttr, ref int nRecLen);

            [DllImport("WinScard.dll")]

            public static extern int SCardTransmit(int hCard, ref SCARD_IO_REQUEST pioSendPci, byte[] pbSendBuffer, int cbSendLength, ref SCARD_IO_REQUEST pioRecvPci, ref byte[] pbRecvBuffer, ref int pcbRecvLength);

            [DllImport("WinScard.dll")]

            public static extern int SCardTransmit(int hCard, ref SCARD_IO_REQUEST pioSendPci, byte[] pbSendBuffer, int cbSendLength, ref SCARD_IO_REQUEST pioRecvPci, ref byte pbRecvBuffer, ref int pcbRecvLength);

    依序下指令:

    SCardEstablishContext:建立環境。

    SCardListReaders:讀取本機的讀卡機。

    SCardConnect:讀卡機連線。

    SCardTransmit:下指令給讀卡機並讀取讀卡機的回覆值。

  • 相关阅读:
    static link:关于gcc连接静态库的几种方式
    gcc同时使用动态和静态链接
    解决 liblog4cpp.a: could not read symbols: Bad value
    lombok 下的@Builder注解用法
    mybatis-plus id主键生成的坑
    关于mybatis-plus 和 mybatis-plus-boot-starter 异同点分析
    解决SpringBoot2.0集成Swagger2访问404的问题
    Google 开源的这个库,性能快到让程序员飞起来!
    解决mybatisplus saveBatch 或者save 无法插入主键问题
    intellij IDEA github clone 指定分支代码
  • 原文地址:https://www.cnblogs.com/bingyun84/p/1515255.html
Copyright © 2020-2023  润新知