SymCrypt can be consumed by .NET projects on Linux using PackageReference. The .NET SDK automatically extracts the native binary libsymcrypt.so from the runtimes/<rid>/native/ directory in the package and places it next to your published output. You can then access the functions via [DllImport("symcrypt")].
Requirements:
- The project must use
PackageReference. - You must specify a
RuntimeIdentifier (e.g., linux-x64 or linux-arm64). - Use
dotnet publish -r <RID> to build the application.
Caveats:
- The package does not include a
libsymcrypt.so.<MAJOR> SONAME symlink. If your runtime loader requires lookup by SONAME, you must manually create the symlink during your publish step. - Non-.NET Linux C/C++ builds are not supported via NuGet. For those, use the Azure Linux
.tar.gz binary distribution directly.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>linux-x64;linux-arm64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SymCrypt" Version="<SymCrypt Package Version>" />
</ItemGroup>
</Project>
using System.Runtime.InteropServices;
internal static class SymCrypt
{
[DllImport("symcrypt")]
public static extern void SymCryptSha256(byte[] data, nuint cbData, byte[] result);
}