nMRTD 0.8.8-alpha

This is a prerelease version of nMRTD.
dotnet add package nMRTD --version 0.8.8-alpha
                    
NuGet\Install-Package nMRTD -Version 0.8.8-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nMRTD" Version="0.8.8-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nMRTD" Version="0.8.8-alpha" />
                    
Directory.Packages.props
<PackageReference Include="nMRTD" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nMRTD --version 0.8.8-alpha
                    
#r "nuget: nMRTD, 0.8.8-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nMRTD@0.8.8-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nMRTD&version=0.8.8-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=nMRTD&version=0.8.8-alpha&prerelease
                    
Install as a Cake Tool

nMRTD

NuGet version Target Framework Native AOT License: LGPL v3

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 covered by an automated test suite (the ported JMRTD tests, unit tests and end-to-end tests against a simulated chip), but the library has been exercised against only a few real-world documents (see Tested documents). 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.

Contents

Features

  • Smart card access layer — a CardService abstraction (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:

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.

Documentation

DOCUMENTATION.md is the technical documentation: the architecture (card service, file system, secure messaging, PassportService API), the access control protocols (BAC, PACE, Chip and Terminal Authentication, Active Authentication), the LDS data groups and the biometric data model, Passive Authentication, and Native AOT and trimming.

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:

  1. 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);
  2. 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);
  3. performs Passive Authentication: checks each data group hash against EF.SOD, verifies the EF.SOD signature (RSA, RSASSA-PSS, ECDSA) with the document signer certificate it contains and, with --csca, checks that this certificate was issued by a Country Signing CA you trust;
  4. performs Chip Authentication when DG14 offers it, and checks it by reading EF.COM with the new session keys;
  5. performs Active Authentication when DG15 is present: the chip signs a random challenge, and the signature (RSA ISO/IEC 9796-2 or ECDSA) is verified with the DG15 public key.

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

# Check the document signer against trusted CSCA certificates, and write the results as JSON
dotnet run --project nMRTD.Cli -f net10.0 -- --can 123456 --csca ./csca --json > result.json
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)
--csca <path> Trusted CSCA certificates: a .cer/.crt/.der/.pem file, an ICAO master list (.ml), or a folder of them
--json Write the results as JSON to stdout; the text output goes to stderr
--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), 2 for a card communication error and 3 for any other error. A failed check (a hash mismatch, an invalid signature, an untrusted CSCA, a failed Chip or Active Authentication) does not change the exit code: with --json the outcome of each check is in the JSON (for example "passiveAuthentication": { "signature": "valid", "csca": "trusted" }). For Chip and Active Authentication, keyAuthenticated tells whether the public key used (DG14 or DG15) is covered by a valid EF.SOD signature: only then does "status": "succeeded" show that the chip is genuine.

With --csca, the document signer certificate is trusted when its signature verifies with one of the given CSCA certificates that is named as its issuer. Get the CSCA certificates from the issuing country (for example its ministry's CSCA page) or from a master list published by a document verification authority, and keep them outside the repository. The tool does not check the signature of a master list, nor revocation (CRLs).

Personal data: the output, the JSON, the --verbose trace and the images saved to --out contain the holder's personal data and photo. Use --out to 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 Active 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) n.a. 1.8
Italian passport ✅ MRZ n.a. ✅ SHA-1 hashes; SHA1withRSA signature ✅ DH 1024-bit, 3DES (id-CA-DH-3DES-CBC-CBC) n.a. 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; these results predate --csca, so that certificate was not validated 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, Chip and Active 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.8.8-alpha 54 11/23/2026
0.8.7-alpha 48 11/23/2026
0.8.6-alpha 65 11/22/2026
0.8.5-alpha 55 11/22/2026
0.8.4-alpha 59 11/22/2026
0.8.2-alpha 47 11/22/2026
0.8.1-alpha 57 11/22/2026
0.8.0-alpha 52 11/21/2026
0.7.1-alpha 53 11/21/2026
0.5.0-alpha 51 11/21/2026
0.4.1-alpha 105 9/1/2026
0.4.0-alpha 82 9/1/2026
0.3.0-alpha 87 8/26/2026
0.2.0-alpha 93 8/23/2026