A comprehensive Java library for reading and processing EMV (Europay, Mastercard, Visa) payment cards, supporting both contact and contactless transactions. Built with Test-Driven Development (TDD) principles and enterprise-level testing standards.
- ISO 7816-4 Compliance - Full Application Identifier (AID) validation
- EMV Transaction Processing - Complete payment card transaction flow
- BER-TLV Data Parsing - Robust EMV data structure handling
- Card Emulation - Software-based card emulation for testing
- Multi-Application Support - Handle multiple payment applications per card
- Contact Cards - Traditional chip card interface
- Contactless Cards - NFC/RFID payment cards
- PSE/PPSE Discovery - Payment System Environment detection
- Application Selection - Automatic and manual app selection
- PIN Verification - Secure PIN handling and validation
- Static Data Authentication (SDA) - Card authenticity verification
- Certificate Chain Validation - CA and issuer certificate processing
- Cryptogram Verification - Transaction cryptogram validation
- Risk Management - Terminal and issuer risk assessment
This project follows strict TDD principles with comprehensive test coverage:
- 123 Total Tests across 8 test classes
- 92% Success Rate (113 passing tests)
- Modern Testing Framework (JUnit 4.13.2, Mockito 3.12.4, AssertJ 3.21.0)
Component | Tests | Success Rate | Coverage |
---|---|---|---|
AID Validation | 10/10 | 100% β | ISO 7816-4 compliance |
BER-TLV Parsing | 14/15 | 93% β | EMV data structures |
Card Emulation | 20/20 | 100% β | Complete functionality |
EMV Session | 9/15 | 60% π | Transaction flow |
Utilities | 60/63 | 95% β | Helper functions |
AIDTest.java
- Application Identifier validationBERTLVTest.java
- EMV data structure parsingCardEmulatorTest.java
- Card emulation testingEMVSessionTest.java
- Transaction flow with MockitoEMVUtilTest.java
- Utility function validation
- Java 11+ (OpenJDK recommended)
- Maven 3.6+ for dependency management
- Smart card reader (optional, for physical cards)
# Clone the repository
git clone https://github.com/hisgarden/javaemvreader.git
cd javaemvreader
# Build the project
mvn clean compile
# Run tests
mvn test
# Create JAR
mvn package
import sasc.emv.*;
import sasc.terminal.*;
// Initialize EMV session
SmartCard card = new SmartCard();
CardConnection terminal = new SmartcardioCardConnection();
EMVSession session = new EMVSession(card, terminal);
// Discover and select applications
session.initContext();
List<EMVApplication> apps = card.getEmvApplications();
// Process transaction
for (EMVApplication app : apps) {
session.selectApplication(app);
session.initiateApplicationProcessing();
session.prepareTransactionProcessing();
session.performTransaction();
}
import sasc.CardEmulator;
// Use built-in card emulation for testing
CardEmulator emulator = new CardEmulator("/sdacardtransaction.xml");
byte[] atr = emulator.getATR();
// Send APDU commands
byte[] selectPSE = EMVAPDUCommands.selectPSE();
CardResponse response = emulator.transmit(selectPSE);
- RUN_TESTS.md - Complete test execution guide
- TDD_IMPROVEMENTS.md - Detailed TDD implementation
- TEST_EXECUTION_REPORT.md - Test analysis and results
- EMVSession - Main transaction processing class
- SmartCard - Card abstraction layer
- CardEmulator - Software card emulation
- EMVUtil - Utility functions for EMV processing
- BERTLV - BER-TLV data structure handling
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=AIDTest
# Run with verbose output
mvn test -X
# Generate test reports
mvn test && open target/surefire-reports/index.html
# Critical EMV components
mvn test -Dtest=AIDTest,BERTLVTest,CardEmulatorTest
# Transaction flow
mvn test -Dtest=EMVSessionTest
# Utility functions
mvn test -Dtest=EMVUtilTest,ApplicationPriorityIndicatorTest
# Clean build
mvn clean compile
# Create JAR with dependencies
mvn package assembly:single
# Install to local repository
mvn install
javaemvreader/
βββ src/main/java/sasc/ # Core EMV implementation
β βββ emv/ # EMV transaction processing
β βββ iso7816/ # ISO 7816-4 standard implementation
β βββ smartcard/ # Smart card abstraction
β βββ terminal/ # Terminal communication
βββ src/test/java/sasc/ # Comprehensive test suite
β βββ emv/ # EMV transaction tests
β βββ iso7816/ # ISO standard tests
βββ src/main/resources/ # Configuration and data files
βββ testkeys/ # Test certificates and keys
βββ docs/ # Documentation
We welcome contributions! Please follow our TDD approach:
- Fork the repository
- Write failing tests first (Red phase)
- Implement minimal code to pass tests (Green phase)
- Refactor and improve (Refactor phase)
- Submit pull request with test coverage
- Follow TDD principles (Red-Green-Refactor)
- Maintain test coverage above 90%
- Use modern testing frameworks (JUnit, Mockito, AssertJ)
- Include comprehensive documentation
- Follow EMV specifications and ISO 7816-4 standards
This project is licensed under the Apache License 2.0 - see the LICENSE-2_0.txt file for details.
- EMV Specifications - Official EMV standards
- ISO 7816 - Smart card standards
- PC/SC - Smart card reader interface
- Issues: GitHub Issues
- Documentation: See
docs/
directory - Email: jin.wen@hisgarden.org
- EMV Consortium for payment card standards
- SASC Community for smart card development
- TDD Community for testing best practices
- Contributors who helped improve this project
Built with β€οΈ using Test-Driven Development principles