4

I write .NETCore servers using CentOS 7 using the JetBrains Rider IDE.

I need to create a bunch of strong named assemblies (library projects) for .NETCore 2.0. I know that on Windows I can use the sn.exe tool to create the snk key files. Can anybody elaborate a bit how to do this on a CentOS machine?

I have found a mono binary also called sn (see man page) which seems to be the sn.exe equivilent but it seems to be pretty old (2003 / 2004) and I am not sure, if it is the tool one should use TODAY.

Also I need to sign some DLLs with an official (from a commerial vendor) code signing certificate. I do NOT understand the relation between a snk file and the certificate I got (it has a p12 extension).

From researching a little bit, I read, that in my .csproj file I need to add the following tags to advice MSBUILD to create strong named assemblies:

<AssemblyOriginatorKeyFile>MyKey.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>

I would greatly appreciate if someone could explain how to (on CentOS 7 targeting .NetCore 2.0):

  1. Create strong named assemblies

  2. Sign an assembly with an existing commercial certificate

Please note that I am NOT using VisualStudio (where you have UI tools)!

ThommyB
  • 1,456
  • 16
  • 34

1 Answers1

1

sn -k sgKey.snk

https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-create-a-public-private-key-pair

It works on Linux. Mono should be installed. Tried with .Net Core 2.2


Some useful command:

Create a key pair: sn –k private.snk

Extract public key: sn –p private.snk public.snk

View public key and public key token: sn –tp public.snk

View public key and public key token of assembly: sn –Tp assembly.dll

Extract public key from assembly: sn –e assembly.dll public.snk

Verify if assembly is signed and with what key: sn –vf assembly.dll

Show list of assemblies on machine registered for verification skipping: sn –Vl

Register assemblies for verification skipping: sn –Vr * (must elevate)

Resign an assembly with the key pair: sn –Ra assembly.dll private.snk

Serge K
  • 615
  • 3
  • 11