nMRTD 0.8.1-alpha
See the version list below for details.
dotnet add package nMRTD --version 0.8.1-alpha
NuGet\Install-Package nMRTD -Version 0.8.1-alpha
<PackageReference Include="nMRTD" Version="0.8.1-alpha" />
<PackageVersion Include="nMRTD" Version="0.8.1-alpha" />
<PackageReference Include="nMRTD" />
paket add nMRTD --version 0.8.1-alpha
#r "nuget: nMRTD, 0.8.1-alpha"
#:package nMRTD@0.8.1-alpha
#addin nuget:?package=nMRTD&version=0.8.1-alpha&prerelease
#tool nuget:?package=nMRTD&version=0.8.1-alpha&prerelease
nMRTD
Status: THIS IS AN EARLY-STAGE PORT: the core protocol stack (BAC, PACE, EAC, Active/Passive Authentication) and the LDS/biometric data model are implemented and build cleanly, but the library has not yet been exercised against a broad range of real-world documents and its automated test suite is still small. Treat it as a foundation to build on and validate for your own use case, not as a production-hardened SDK yet.
Please note: this project is AI-assisted.
nMRTD is a .NET 6/8/10 library for reading electronic Machine Readable Travel Documents (eMRTDs) — biometric passports, electronic ID cards, and similar ICAO-compliant documents — over NFC/contactless smart card readers, implementing the ICAO Doc 9303 specification.
It is a from-scratch C# port of JMRTD, the reference Java implementation of the MRTD standards, targeting .NET 6/8/10, Native AOT (.NET 8 and 10), and cross-platform smart card access (Windows, Linux, macOS) via PC/SC.
Features
- Smart card access layer — a
CardServiceabstraction (command/response APDUs, file system, TLV utilities) with a cross-platform PC/SC implementation (PCSC/PCSC.Iso7816) working over WinSCard on Windows and PC/SC-lite on Linux/macOS. - Access-control and secure-messaging protocols:
- BAC (Basic Access Control), keyed from the MRZ.
- PACE (Password Authenticated Connection Establishment), keyed either from the MRZ or from the document's CAN (Card Access Number).
- EAC (Extended Access Control): Chip Authentication and Terminal Authentication (BSI TR-03110), including Card Verifiable (CV) certificate parsing/building.
- Active Authentication.
- Secure Messaging (DESede and AES) wrapping every subsequent APDU exchange.
- LDS (Logical Data Structure) parsing — EF.COM, EF.SOD, and data groups DG1 through DG16 (MRZ, facial/fingerprint/iris images, additional personal/document details, security infos, and more), plus Passive Authentication: verifying each data group's hash and the EF.SOD's CMS/PKCS#7 signature.
- Biometric data models for both ISO/IEC 19794 (face/finger/iris, the common case) and the newer ISO/IEC 39794 standard, wrapped per CBEFF (ISO/IEC 7816-11).
- Native AOT and trimming friendly, with no reflection-based dispatch or serialization — built to publish as a self-contained native executable on any of the supported platforms.
Installation
Add the package to your .NET project:
dotnet add package nMRTD
or reference it directly in your .csproj:
<ItemGroup>
<PackageReference Include="nMRTD" />
</ItemGroup>
nMRTD targets .NET 6/8/10 and depends on the following transitive dependencies:
BouncyCastle.Cryptography(crypto/ASN.1)PCSCPCSC.Iso7816(smart card access)
Quick start
Reading a document with BAC
using nMRTD;
using nMRTD.Lds.Icao;
using nMRTD.SmartCards;
// Connect to the first available PC/SC reader.
var cardService = new PcscCardService();
var passportService = new PassportService(
cardService,
PassportService.NormalMaxTransceiveLength,
PassportService.DefaultMaxBlocksize,
isSfiEnabled: true,
shouldCheckMac: true);
passportService.Open();
// Authenticate with Basic Access Control, keyed from the printed MRZ.
var bacKey = new BacKey(
documentNumber: "L898902C3",
dateOfBirth: "740812", // yyMMdd
dateOfExpiry: "120415"); // yyMMdd
passportService.SendSelectApplet(false);
passportService.DoBAC(bacKey);
// Read and parse EF.DG1 (the MRZ).
using Stream dg1Stream = passportService.GetInputStream(PassportService.EF_DG1);
var dg1 = new DG1File(dg1Stream);
Console.WriteLine($"Document number: {dg1.GetMRZInfo().GetDocumentNumber()}");
// Read and parse EF.DG2 (the facial image).
using Stream dg2Stream = passportService.GetInputStream(PassportService.EF_DG2);
var dg2 = new DG2File(dg2Stream);
passportService.Close();
Authenticating with PACE, via MRZ or CAN
Most current documents advertise PACE support in EF.CardAccess; prefer it over BAC when available:
using nMRTD;
using nMRTD.Lds;
using nMRTD.SmartCards;
using Stream cardAccessStream = passportService.GetInputStream(PassportService.EF_CARD_ACCESS);
var cardAccessFile = new CardAccessFile(cardAccessStream);
PACEInfo paceInfo = cardAccessFile.GetSecurityInfos().OfType<PACEInfo>().First();
var parameterId = paceInfo.GetParameterId()!;
object staticParameters = PACEInfo.ToParameterSpec(parameterId);
// Option A -- derive the PACE key from the MRZ, same details as for BAC:
IAccessKeySpec paceKey = PaceKeySpec.CreateMrzKey(
new BacKey("L898902C3", "740812", "120415"));
// Option B -- derive the PACE key from the Card Access Number printed on the
// document instead. A CAN can *only* be used for PACE, never for BAC.
// IAccessKeySpec paceKey = PaceKeySpec.CreateCanKey("500540");
passportService.DoPace(paceKey, paceInfo.GetObjectIdentifier(), staticParameters, parameterId);
passportService.SendSelectApplet(true);
// From here on, read DG1/DG2/... exactly as in the BAC example above.
For a complete, runnable example covering reader selection, PACE-with-BAC-fallback, DG1/DG2 parsing, full Passive Authentication (EF.SOD hash and signature verification) and Chip Authentication, see the command-line tool and its source, nMRTD.Cli/Program.cs.
Command-line tool (nMRTD.Cli)
The repository includes nMRTD.Cli, a console application that reads a document end to end with
nMRTD. It is a sample and a test tool: it is not part of the NuGet package. It needs a
contactless (NFC) PC/SC reader; contact-only smart card readers and phones are not supported.
For each document it:
- opens the reader and authenticates with PACE (using EF.CardAccess), falling back to BAC
when the document does not support PACE (or uses BAC directly with
--bac); - reads every standard data group except DG3 and DG4 (fingerprints and iris need Terminal Authentication), printing a summary and a hex dump of each, and saves the images (DG2, DG5–DG7);
- performs Passive Authentication: checks each data group hash against EF.SOD and verifies the EF.SOD signature (RSA, RSASSA-PSS, ECDSA) with the document signer certificate it contains;
- performs Chip Authentication when DG14 offers it, and checks it by reading EF.COM with the new session keys.
Run it from the repository root:
# List the PC/SC readers
dotnet run --project nMRTD.Cli -f net10.0 -- --list-readers
# Card Access Number (PACE only)
dotnet run --project nMRTD.Cli -f net10.0 -- --can 123456 --out ./out
# MRZ access key: document number (without check digit), date of birth and date of expiry (yyMMdd)
dotnet run --project nMRTD.Cli -f net10.0 -- --doc L898902C3 --dob 740812 --doe 120415 --out ./out
# Same, skipping PACE and using BAC
dotnet run --project nMRTD.Cli -f net10.0 -- --doc L898902C3 --dob 740812 --doe 120415 --bac --out ./out
| Option | Meaning |
|---|---|
--can <CAN> |
Card Access Number (PACE only; cannot be used for BAC) |
--doc <number> --dob <yyMMdd> --doe <yyMMdd> |
MRZ access key; --can and the MRZ options are alternatives |
--bac |
Skip PACE and use BAC with the MRZ access key |
--reader <name> |
PC/SC reader to use (default: the first one found) |
--out <dir> |
Folder for the extracted images (default: the current folder) |
--verbose |
Print the APDU exchanges and protocol steps to stderr |
--list-readers |
List the PC/SC readers and exit |
-h, --help |
Show the help |
Without --can or the MRZ options, the tool asks which access key to use. The exit code is 0 on
success, 1 for invalid arguments (or a CAN on a document without PACE) and 2 for a card
communication error.
Personal data: the output, the
--verbosetrace and the images saved to--outcontain the holder's personal data and photo. Use--outto write the images outside the repository, and do not share the output or traces unredacted.
The tool also publishes as a Native AOT executable for net8.0 and net10.0:
dotnet publish nMRTD.Cli -c Release -f net10.0 -r win-x64
Tested documents
Results of reading real documents with nMRTD.Cli (nMRTD 0.8.0-alpha, Windows, REINER SCT
cyberJack RFID basis reader), as a JIT build and as a Native AOT executable.
| Document | BAC | PACE | Passive Authentication | Chip Authentication | LDS |
|---|---|---|---|---|---|
| Italian identity card (CIE 3.0) | ✅ MRZ | ✅ CAN; DH, Generic Mapping, 3DES (id-PACE-DH-GM-3DES-CBC-CBC) |
✅ SHA-512 hashes; RSASSA-PSS SHA-512 signature | ✅ DH 2048-bit, 3DES (id-CA-DH-3DES-CBC-CBC) |
1.8 |
| Italian passport | ✅ MRZ | n.a. | ✅ SHA-1 hashes; SHA1withRSA signature | ✅ DH 1024-bit, 3DES (id-CA-DH-3DES-CBC-CBC) |
1.7 |
These two documents do not cover:
- PACE and Chip Authentication with elliptic curves or AES;
- Active Authentication (neither document has DG15);
- Terminal Authentication, which needs terminal certificates issued by a national document verifier to read the fingerprints (DG3).
Passive Authentication here checks the document signature with the signer certificate stored in EF.SOD; it does not validate that certificate against the issuing country's CSCA.
Please help extend this table. If you read another document with
nMRTD.Cli(another country, another document type, or the same document with a different access method), please open an issue with the document type and issuing country, the reader and operating system, and the BAC, PACE, Passive Authentication and Chip Authentication lines of the output, including any error. Leave out names, document numbers, dates, photos and hex dumps: the protocol and algorithm lines are all that is needed.
Tests
dotnet test nMRTD.sln
dotnet test nMRTD.sln --collect:"XPlat Code Coverage"
The tests run on all three target frameworks. With --collect, coverlet writes a
coverage.opencover.xml for each framework under nMRTD.Tests/TestResults/ (the format is set in
nMRTD.Tests/coverage.runsettings).
License
nMRTD is a derivative work: a from-scratch C# port of JMRTD, originally written in Java by the JMRTD team. All credit for the original design, protocol implementation, and years of ICAO 9303 domain expertise belongs to them; this project would not exist without their work. nMRTD is not affiliated with or endorsed by the JMRTD project.
Like its upstream, nMRTD is distributed under the terms of the GNU Lesser General Public License v3 (LGPL-3.0). See the LICENSE file for the full license text.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- BouncyCastle.Cryptography (>= 2.6.2)
- PCSC (>= 7.0.1)
- PCSC.Iso7816 (>= 7.0.1)
-
net6.0
- BouncyCastle.Cryptography (>= 2.6.2)
- PCSC (>= 7.0.1)
- PCSC.Iso7816 (>= 7.0.1)
-
net8.0
- BouncyCastle.Cryptography (>= 2.6.2)
- PCSC (>= 7.0.1)
- PCSC.Iso7816 (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.0-alpha.1 | 70 | 11/29/2026 |
| 0.8.12-alpha.1 | 68 | 11/28/2026 |
| 0.8.11-alpha | 63 | 11/28/2026 |
| 0.8.10-alpha | 65 | 11/28/2026 |
| 0.8.9-alpha | 72 | 11/27/2026 |
| 0.8.8-alpha | 73 | 11/23/2026 |
| 0.8.7-alpha | 63 | 11/23/2026 |
| 0.8.6-alpha | 79 | 11/22/2026 |
| 0.8.5-alpha | 68 | 11/22/2026 |
| 0.8.4-alpha | 72 | 11/22/2026 |
| 0.8.2-alpha | 62 | 11/22/2026 |
| 0.8.1-alpha | 68 | 11/22/2026 |
| 0.8.0-alpha | 64 | 11/21/2026 |
| 0.7.1-alpha | 63 | 11/21/2026 |
| 0.5.0-alpha | 64 | 11/21/2026 |
| 0.4.1-alpha | 112 | 9/1/2026 |
| 0.4.0-alpha | 85 | 9/1/2026 |
| 0.3.0-alpha | 92 | 8/26/2026 |
| 0.2.0-alpha | 96 | 8/23/2026 |