Inhaltsverzeichnis

5. Integration

In this chapter you'll learn how to integrate OpenSSL into your .NET applications.


Overview

Topic Description Page
——-————-——
P/Invoke Integrate DLLs in .NET 5.1 P/Invoke - Integrate DLLs
Blazor WASM Use WASM in browser blazor-wasm
NuGet Create and use packages 5.2 NuGet Basics

Quick Start

1. Copy DLLs

# To your .NET project directory
copy "D:\Projects\openssl-3.6.0\bin\bin\libcrypto-3-x64.dll" .\
copy "D:\Projects\openssl-3.6.0\bin\bin\libssl-3-x64.dll" .\

2. Modify .csproj

<ItemGroup>
  <None Update="libcrypto-3-x64.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
  <None Update="libssl-3-x64.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

3. Use P/Invoke

using System.Runtime.InteropServices;
 
public static class OpenSsl
{
    [DllImport("libcrypto-3-x64.dll")]
    public static extern int OPENSSL_init_crypto(ulong opts, IntPtr settings);
}

Which Integration Fits You?

Application Type Recommendation
———————————-
.NET Console/WinForms/WPF P/Invoke
ASP.NET Core API P/Invoke
Blazor WebAssembly WASM Integration
Blazor Server P/Invoke
Library for others NuGet Package

Continue to


Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional