This page shows how to use CryptoSys PKI with .NET Core (dotnetcore) on Windows. It is similar to the instructions on how to use FirmaSAT with .NET core.
Prerequisites | Principles | A simple test | Instructions | Full .NET Tests | Using Visual Studio Code | Contact us
diCrPKI.dll
must exist in your application's
Library Search Path.
¶ We use the word "core" in our documentation to refer to the "core" of the CryptoSys PKI application,
the native Windows DLL file diCrPKI.dll
. Don't get confused with "dotnet core".
The .NET interface library file diCrSysPKINet.dll
provided with the CryptoSys PKI distribution
works with both the standard .NET Framework and .NET Core. You just need to set a reference to it in your dotnetcore project file.
All the example C# source code modules provided in the distribution and elsewhere on this site works on .NET Core without alteration (** except for one small edit).
A copy of the file diCrSysPKINet.dll
is installed by default in the folder C:\Program Files (x86)\CryptoSysPKI\DotNet
(or C:\Program Files\CryptoSysPKI\DotNet
on a 32-bit platform).
You can refer to this directly as a "hint" in your project file: a copy will be made in the \bin
subdirectory when you first build the project.
The equivalent of an "Hello World!" program for CryptoSys PKI is to print the version number of the native CryptoSys PKI DLL
using the General.Version()
method.
Here is the code module pki_simple.cs
. Note the using CryptoSysPKI;
line.
// pki_simple.cs using System; using CryptoSysPKI; namespace pki_simple { class Program { static void Main(string[] args) { Console.WriteLine("Version = {0}", General.Version()); } } }Expected output (similar to):
Version = 200000If this works OK, it shows you have done things correctly and you can move on to more complicated projects.
> dotnet new console -n pki_simple -o pki_simpleThis should display:
The template "Console Application" was created successfully. ...etc. Restore succeeded.This will create a new subdirectory called
pki_simple
with the following structure.
\---pki_simple | pki_simple.csproj | Program.cs | \---obj project.assets.json project.nuget.cache ... etc.
cd pki_simple
Program.cs
to pki_simple.cs
and edit it to match the above code.
Or just copy the new file pki_simple.cs
and delete Program.cs
.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <!-- BEGIN ADD THIS --> <ItemGroup> <Reference Include="diCrSysPKINet"> <SpecificVersion>False</SpecificVersion> <HintPath>C:\Program Files (x86)\CryptoSysPKI\DotNet\diCrSysPKINet.dll</HintPath> </Reference> </ItemGroup> <!-- END ADD THIS --> </Project>Note we can use a hard-coded reference to
diCrSysPKINet.dll
in the HintPath because a copy will be made in our local bin directory when the project is built.
If you used a different directory when installing CryptoSys PKI, you will need to change the HintPath to match.
> dotnet buildIf this works OK, it should show
Build succeeded.
0 Warning(s)
0 Error(s)
> dotnet runExpected output:
Version = 200000
bin\Debug\netcoreapp3.1
.
\---pki_simple
| pki_simple.cs
| pki_simple.csproj
|
+---bin
| \---Debug
| \---netcoreapp3.1
| diCrSysPKINet.dll
| pki_simple.deps.json
| pki_simple.dll
| pki_simple.exe
| pki_simple.pdb
| pki_simple.runtimeconfig.dev.json
| pki_simple.runtimeconfig.json
|
which you can run directly
> .\bin\Debug\netcoreapp3.1\pki_simple.exe Version = 200000
The full .NET tests provided in the distribution work exactly the same as with the .NET Framework. The source code module TestPKIcsharp.cs is unchanged (** except for one small edit).
The setup in dotnetcore uses similar instructions as above, but we need to add a subdirectory for the test files, and add an instruction for the starting working directory to the project file.
The test files are included in the distribution in the file pkiDotNetTestFiles.zip.
dotnet new console -n TestPKIcsharp -o TestPKIcsharp
Project.cs
with TestPKIcsharp.cs, then edit the file:
// test_Cnv_other();
It seems the tests using Encoding.GetEncoding(1252)
are not supported in dotnetcode.
pkiDotNetTestFiles
. So the file structure should now be as follows.
\---TestPKIcsharp | TestPKIcsharp.cs | TestPKIcsharp.csproj | +---pkiDotNetTestFiles | alice-lamps.crt | alice-lamps.p12 | AlicePrivRSASign.p8e | AlicePubRSA.pub | AliceRSAPSS.p8 | AliceRSAPSS.p8e | ... etc. \---obj project.assets.json project.nuget.cache ... etc.
ItemGroup/Reference
as above,
plus a StartWorkingDirectory
element so the program will start in the directory with the test files
(the program assumes the test files are in its current working directory).
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <PropertyGroup> <StartWorkingDirectory>.\pkiDotNetTestFiles\</StartWorkingDirectory> </PropertyGroup> <ItemGroup> <Reference Include="diCrSysPKINet"> <SpecificVersion>False</SpecificVersion> <HintPath>C:\Program Files (x86)\CryptoSysPKI\DotNet\diCrSysPKINet.dll</HintPath> </Reference> </ItemGroup> </Project>
dotnet build
dotnet run
PKI Version is 200000 Local directory is 'C:\...\DotNetCore\pki\TestPKIcsharp\bin\Debug\netcoreapp3.1'. Checking required test files are in local directory... Creating test sub-directory 'pkitest.09385729' CWD is C:\...\DotNetCore\pki\TestPKIcsharp\pkiDotNetTestFiles\pkitest.09385729 DOING ALL TESTS... GENERAL FUNCTIONS: Version=200000 LicenceType=D ModuleName=C:\WINDOWS\SYSTEM32\diCrPKI.dll ...[cut]... TESTING TRIPLE DES: KY=010101010101010101010101010101010101010101010101 PT=8000000000000000 CT=95F8A5E5DD31D900 OK=95F8A5E5DD31D900 P'=8000000000000000 OK=8000000000000000 CT=95F8A5E5DD31D900 ...[cut]... ALL TESTS COMPLETED. CWD reset to C:\...\DotNetCore\pki\TestPKIcsharp\pkiDotNetTestFiles Removing test directory 'pkitest.09385729'
(Version and compile time may vary)
You can use the free Visual Studio Code to analyse and even run your dotnetcode project.
code .
(that's the word "code" followed by a space and a dot).
code .This will open up Visual Studio Code and show all your project files in the VSCode explorer window. You can even run your project from the IDE, but you may get a lot of unnecessary warnings, etc.
To contact us or comment on this page, please send us a message.
This page first published 18 November 2020. Last updated 18 December 2024.