Table of Contents
This repository contains a Visual Studio 2019 solution with sample code in C# that uses Microsoft .NET Cryptography Model with YubiKey 5 PIV.
The C# code in YubiKeyPivSign.cs
demonstrates how to sign some data with a YubiKey 5 PIV on Windows 10.
The YubiKey 5 PIV is accessed from Microsoft .NET Cryptography Model by using the underlying Microsoft Base Smart Card Crypto Provider
.
To get started with the project follow the steps below.
Use a PC with Windows 10 or higher as operating system.
Download and install Microsoft Visual Studio 2019.
A X.509 certificate needs to be enrolled to the YubiKey 5 PIV before using this sample code for signing. For test purposes, it is possible to use the Yubico .NET YubiKey SDK to generate a key-pair and generate a self-signed certificate on the YubiKey 5 PIV.
-
Clone the repo
git clone https://github.com/YubicoLabs/Microsoft.Net-Crypto-YubiKey.git
-
Open the solutions file
Microsoft.Net-Crypto-YubiKey.sln
with Microsoft Visual Studio 2019. -
Select the menu item "Build" and select the option "Build Solution".
Insert a YubiKey 5 with a X.509 certificate in the USB-port at the PC.
Run the application by either pressing the button "Microsoft.Net-Crypto-YubiKey" in the top bar of Microsoft Visual Studio 2019 (see the image above), or running the executable file <file path to the solution>\Microsoft.Net-Crypto-YubiKey\bin\Debug\net5.0\Microsoft.Net-Crypto-YubiKey.exe
.
This will launch a command prompt, which in turn will present the Windows Security dialog box for a Smart Card. Enter the PIN code to the YubiKey 5 PIV in this dialog box.
Distributed under the Apache License 2.0. See LICENSE
for more information.
Please contact the Yubico solutions developer program if you have any questions.
Website: https://developers.yubico.com/
Email: [email protected]
More information on how to use hardware modules and smart cards with Microsoft .NET is available at Microsoft's web: How to Access Hardware Encryption Devices.