How to sign C++ assemblies with a strong name

21 10 2012

Strong Name (SN) is a technology introduced with the .NET platform, which gives a globally unique identity to the applications or components. If our application is signed with a strong name, then it is mandatory to sign all assemblies it refer.

In case if you are working in COM dll or Managed C++ library, you may need to provide signed version of your DLL to client applications.

First step is to create a key file using sn.exe tool which we can find out with .NET Framework SDK,

sn.exe -k [Directory]\MyKey.snk

Sign COM Interop DLLs

If we are working on COM dlls, generally we generate ineterop DLLs too for .NET client applications. This can be generated by tlbimp.exe.
Tlbimp.exe provides the functionality to set a /keyfile: as an argument to generate the interop dll which is signed with a Strong Name.

The following commands shall be added to the project’s post build events.

tlbexp MyComDll.dll /out:MyComDll.tlb
tlbimp MyComDll.tlb /keyfile:MyKey.snk /namespace:Company.MyComDll /output:Interop.MyComDll.dll

Sign Managed C++ library

A managed DLL can be signed by specifying the key file in visual studio project settings at Project-> Properties-> Configuration Properties-> Linker-> Advanced-> Key File

We can check whether our DLLs are signed or not using same SN.EXE tool. The following command will give key information.

sn.exe -T MySignedDll.dll



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: