This project contains a PC/SC wrapper and smartcard abstraction layer.
The project is provided as a self-contained Gradle project and should compile without problems.
A pre-built jar file is available in the "dist" folder.
On the most basic layer, we simply use a declarative approach to wrap PC/SC API functions. To work on this "abstraction" you can simply usede.intarsys.security.smartcard.pcsc.nativec._PCSC.
If you create this without parameter, the default library for the platform will be used.
There's a small abstract layer aroundde.intarsys.security.smartcard.pcsc.nativec._PCSC that allows for a little bit more readable code and also includes some indirections to ease life with 3rd-party libraries and workarounds for them.
In the "examples" directory you will find some demo code.
The most simple use case is
IPCSCContext context = PCSCContextFactory.get().establishContext();List<IPCSCCardReader> readers = context.listReaders();if (readers.isEmpty()) { System.out.println("no reader found"); return;}for (IPCSCCardReader reader : readers) { PCSCStatusMonitor monitor = new PCSCStatusMonitor(reader); monitor.addStatusListener(new IStatusListener() { @Override public void onException(IPCSCCardReader reader, PCSCException e) { e.printStackTrace(); } @Override public void onStatusChange(IPCSCCardReader reader, PCSCCardReaderState cardReaderState) { System.out.println("reader " + reader + " state " + cardReaderState); } });}
To connect to a reader
// recommended use: create a new context for the connectionSystem.out.println("" + reader + " establish context");IPCSCContext connectionContext = reader.getContext().establishContext();System.out.println("" + reader + " connect");IPCSCConnection connection = connectionContext.connect("example", reader.getName(), _IPCSC.SCARD_SHARE_SHARED, _IPCSC.SCARD_PROTOCOL_Tx);System.out.println("" + reader + " begin transaction");connection.beginTransaction();System.out.println("" + reader + " end transaction");connection.endTransaction(_IPCSC.SCARD_LEAVE_CARD);System.out.println("" + reader + " disconnect");connection.disconnect(_IPCSC.SCARD_LEAVE_CARD);System.out.println("" + reader + " dispose context");connectionContext.dispose();
BSD 3-Clause LicenseCopyright (c) 2013, intarsys GmbHRedistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Service & support should be funneled through the tools available with GitHub.