CryptoSys Home > FirmaSAT > Using FirmaSAT with .NET Core

Using FirmaSAT with .NET Core


This page shows how to use FirmaSAT with .NET Core (dotnetcore).
New2024-09-13: This page updated from dotnet core 3.1 to 8.0.
It is similar to the instructions on how to use Using CryptoSys PKI with .NET Core.

Prerequisites | Principles | A simple test | Instructions | Full .NET Tests | Using Visual Studio Code | Contact us

Prerequisites

  1. You must have installed FirmaSAT on your system, available here. That is, the core DLL file diFirmaSAT2.dll must exist in your application's Library Search Path.
  2. Only Windows is supported. There is currently no option for Linux or Mac.
  3. You have installed .NET Core. We will be using the command-line interface (dotnet CLI). These instructions were written using .NET Core 8.0 (Note this was originally written for .NET Core 3.1 - there are no differences for 8.0, except the number; everything still works as before).

We use the word "core" in our documentation to refer to the "core" of the FirmaSAT application, the native Windows DLL file diFirmaSAT2.dll. Don't get confused with "dotnet core".

Principles

The .NET interface library file diFirmaSatNet.dll provided with the FirmaSAT 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.

A copy of the file diFirmaSatNet.dll is installed by default in the folder C:\Program Files (x86)\FirmaSAT ( or C:\Program Files\FirmaSAT 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.

A simple test

The equivalent of an "Hello World!" program for FirmaSAT is to print the version number of the native FirmaSAT DLL using the General.Version() method.

Here is the code module firmasat_simple.cs. Note the using FirmaSAT; line.

// firmasat_simple.cs

using System;
using FirmaSAT;

namespace firmasat_simple
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Version = {0}", General.Version());
        }
    }
}
Expected output (similar to):
Version = 90182
If this works OK, it shows you have done things correctly and you can move on to more complicated projects.

Instructions

  1. Create a new dotnet project. Open a command-line console and type
    > dotnet new console -n firmasat_simple -o firmasat_simple
    
    This should display:
    The template "Console Application" was created successfully.
    ...etc.
    Restore succeeded.
    
    This will create a new subdirectory called firmasat_simple with the following structure.
    \---firmasat_simple
        |   firmasat_simple.csproj
        |   Program.cs
        |
        \---obj
                project.assets.json
                project.nuget.cache
                ... etc.
    
  2. Change directory into this subdirectory:
    cd firmasat_simple
    
  3. Rename and edit the program code. Rename the file Program.cs to firmasat_simple.cs and edit it to match the above code. Or just copy the new file firmasat_simple.cs and delete Program.cs.
  4. Add a reference in the project file. Edit the .csproj file as follows. Add an ItemGroup element with a Reference to the .NET library DLL.
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
      <!-- BEGIN ADD THIS -->
      <ItemGroup>
        <Reference Include="diFirmaSatNet">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files (x86)\FirmaSAT\diFirmaSatNet.dll</HintPath>
        </Reference>
      </ItemGroup>
      <!-- END ADD THIS -->
    </Project>
    
    Note we can use a hard-coded reference to diFirmaSatNet.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 FirmaSAT, you will need to change the HintPath to match.
  5. Build the project.
    > dotnet build
    
    If this works OK, it should show
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    
  6. Run it.
    > dotnet run
    
    Expected output:
    Version = 107034
    
The actual EXE file is created by default in the subdirectory bin\Debug\netcoreapp3.1.
\---firmasat_simple
    |   firmasat_simple.cs
    |   firmasat_simple.csproj
    |
    +---bin
    |   \---Debug
    |       \---netcoreapp8.0
    |               diFirmaSatNet.dll
    |               firmasat_simple.deps.json
    |               firmasat_simple.dll
    |               firmasat_simple.exe
    |               firmasat_simple.pdb
    |               firmasat_simple.runtimeconfig.dev.json
    |               firmasat_simple.runtimeconfig.json
    |
which you can run directly
> .\bin\Debug\netcoreapp3.1\firmasat_simple.exe
Version = 107034

Full .NET Tests

The full .NET tests provided in the distribution work exactly the same as with the .NET Framework. The source code module TestFirmaSat.cs is unchanged.

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 FirmaSATtestfiles.zip.

  1. Create a new project
    dotnet new console -n TestFirmaSat -o TestFirmaSat
    
  2. Change to the new directory
    cd TestFirmaSat
    
  3. Replace Project.cs with TestFirmaSat.cs.
  4. Add the test files in the subdirectory FirmaSATtestfiles. So the file structure should now be as follows.
    \---TestFirmaSat
        |   TestFirmaSat.cs
        |   TestFirmaSat.csproj
        |
        +---FirmaSATtestfiles
        |       A7.xml
        |       AAA010101AAA201501BN-base.xml
        |       AAA010101AAA201501CT-base.xml
        |       AAA010101AAA201501CT_new-signed.xml
        |       AAA010101AAA201705CT.xml
        |       ... etc.
        \---obj
                project.assets.json
                project.nuget.cache
                ... etc.
    
  5. Edit the .csproj file as follows, with the same 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>.\FirmaSATtestfiles\</StartWorkingDirectory>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="diFirmaSatNet">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files (x86)\FirmaSAT\diFirmaSatNet.dll</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
    
  6. Build the project.
    dotnet build
    
  7. Run it
    dotnet run
    

Expected output

INTERROGATE THE CORE DIFIRMASAT DLL:
Version=90182
CompileTime=May 27 2020 06:24:18
ModuleName=C:\WINDOWS\SYSTEM32\diFirmaSAT2.dll
...
Current working directory is C:\DotNetCore\diFirmaSatNet\TestFirmaSat\FirmaSATtestfiles

FORM THE PIPESTRING FROM AN XML FILE:
Sat.MakePipeStringFromXml('cfdv33a-base.xml')=
||3.3|A|123ABC|2017-12-04T01:23:59|02|...[cut]...||

SIGN AN XML FILE:
Sat.SignXml('cfdv33a-base.xml'-->'cfdv33a_new-signed.xml') returns 0
Sat.ValidateXml('cfdv33a_new-signed.xml') returns 0

...[cut]...

(Version and compile time may vary)

Using Visual Studio Code

You can use the free Visual Studio Code to analyse and even run your dotnetcode project.

Really neat trick to open VS Code

With the command line prompt open in your project directory, just type 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.

Contact us

To contact us or comment on this page, please send us a message.

[Go to top]

This page first published 9 December 2019. Completely rewritten 7 July 2020. Last updated 15 August 2025.