nMRTD 0.8.10-alpha
See the version list below for details.
dotnet add package nMRTD --version 0.8.10-alpha
NuGet\Install-Package nMRTD -Version 0.8.10-alpha
<PackageReference Include="nMRTD" Version="0.8.10-alpha" />
<PackageVersion Include="nMRTD" Version="0.8.10-alpha" />
<PackageReference Include="nMRTD" />
paket add nMRTD --version 0.8.10-alpha
#r "nuget: nMRTD, 0.8.10-alpha"
#:package nMRTD@0.8.10-alpha
#addin nuget:?package=nMRTD&version=0.8.10-alpha&prerelease
#tool nuget:?package=nMRTD&version=0.8.10-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 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 and .NET Framework 4.6.2/4.7.2 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 and .NET Framework 4.6.2/4.7.2, Native AOT (.NET 8 and 10), and cross-platform smart card access (Windows, Linux, macOS) via PC/SC. Its version numbers are its own; the current code is based on JMRTD 0.8.11-SNAPSHOT (upstream commit bb62243e) and SCUBA 0.1.0, and each release says its base in the release notes.
Contents
- Features
- Installation
- Quick start
- Documentation
- Command-line tool (nMRTD.Cli)
- Tested documents
- Tests
- License
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 .NET Framework 4.6.2/4.7.2 and depends on the following transitive dependencies:
BouncyCastle.Cryptography(crypto/ASN.1)PCSCPCSC.Iso7816(smart card access)
On .NET Framework it also depends on System.Memory,
Microsoft.Bcl.HashCode and
Portable.System.DateTimeOnly (the DateOnly
type of the MRZ and certificate dates). Both builds are tested on the .NET Framework 4.8.1 runtime, which runs
them in place of 4.6.2 and 4.7.2. The command-line tool targets .NET 6/8/10 only.
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, PassportService.DefaultMaxBlocksize);
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, PassportService.DefaultMaxBlocksize);
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, PassportService.DefaultMaxBlocksize);
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 reading flow, nMRTD.Cli/DocumentReader.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, through a contactless (NFC) PC/SC reader, to test the library and to verify documents. It
is not part of the NuGet package. It authenticates with PACE (falling back to BAC), reads the data
groups, and runs Passive Authentication (optionally checking the Document Signer against trusted CSCA
certificates), Chip Authentication and Active Authentication. The result is text, JSON or XML, with
the parsed data groups and their images on request, and the exit code is negative for each kind of
problem (a failed check, a rejected access key, no reader...).
dotnet run --project nMRTD.Cli -f net10.0 -- --can 123456
dotnet run --project nMRTD.Cli -f net10.0 -- --doc L898902C3 --dob 740812 --doe 120415 --csca ./csca --output-json > result.json
dotnet run --project nMRTD.Cli -f net10.0 -- --can 123456 --include-information --share --output-json
CLI.md documents the options, each step, the exit codes, the text, JSON and XML outputs, Native AOT publishing and troubleshooting.
Personal data: with
--include-informationor--include-rawthe result contains the holder's personal data and photo, and so does the--verbosetrace. Use--sharefor a result to share.
Tested documents
Results of reading real documents with nMRTD.Cli (Windows 11, REINER SCT cyberJack RFID basis
reader), as a JIT build and as a Native AOT executable. Both documents were first read with nMRTD
0.8.0-alpha and read again with nMRTD 0.8.9-alpha, with the same results; the passport also offers
PACE, which the first reading did not use.
| Document | BAC | PACE | Passive Authentication | Chip Authentication | Active Authentication | LDS |
|---|---|---|---|---|---|---|
| Italian identity card (CIE 3.0) | ✅ MRZ | ✅ CAN; DH 2048-bit (parameter id 2), Generic Mapping, 3DES (id-PACE-DH-GM-3DES-CBC-CBC) |
✅ SHA-512 hashes; RSASSA-PSS SHA-512 signature; Document Signer issued by the Italian CSCA | ✅ DH 2048-bit, 3DES (id-CA-DH-3DES-CBC-CBC) |
n.a. | 1.8 |
| Italian passport | ✅ MRZ | ✅ MRZ; DH 2048-bit (parameter id 2), Generic Mapping, 3DES (id-PACE-DH-GM-3DES-CBC-CBC) |
✅ SHA-1 hashes; SHA1withRSA signature; Document Signer issued by the Italian CSCA | ✅ 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 is complete: the data group hashes and the EF.SOD signature are checked,
and with --csca the Document Signer certificate was found to be issued by a CSCA certificate
published by the Italian Ministry of the Interior. With the CSCA's CRL, the CIE's Document Signer is
not revoked; the passport's was issued under the CSCA's earlier name, which the current CRL does not
cover.
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 output of these two runs, which has all that is needed (document type and issuing state, LDS version, reader, operating system, protocols and key sizes, the outcome of every check) and leaves out names, document numbers, dates and photos:nMRTD.Cli --can <CAN> --share nMRTD.Cli --doc <number> --dob <yyMMdd> --doe <yyMMdd> --bac --share
Tests
dotnet test nMRTD.sln
dotnet test nMRTD.sln --collect:"XPlat Code Coverage"
The tests run on all five target frameworks (the CLI tests on .NET 6/8/10 only). 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. |
| .NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- BouncyCastle.Cryptography (>= 2.6.2)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- PCSC (>= 7.0.1)
- PCSC.Iso7816 (>= 7.0.1)
- Portable.System.DateTimeOnly (>= 9.0.0)
- System.Memory (>= 4.6.3)
-
.NETFramework 4.7.2
- BouncyCastle.Cryptography (>= 2.6.2)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- PCSC (>= 7.0.1)
- PCSC.Iso7816 (>= 7.0.1)
- Portable.System.DateTimeOnly (>= 9.0.0)
- System.Memory (>= 4.6.3)
-
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 |