45

I have an assembly which is not strong-named. I have no source code for it.

I now need it to be signed. Is there a way to do this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
guaike
  • 2,471
  • 9
  • 31
  • 42

5 Answers5

21

If the original assembly is marked for delayed signing, then you can use the sn.exe tool.

If the original assembly is not so marked, then you can disassemble it with ildasm.exe, then re-asssemble it with ilasm.exe and specify the /key argument. References: [1] [2].

Example:

> ildasm /all /out=MYASSEMBLY.il MYASSEMBLY.dll
> ilasm /dll /key=key.snk MYASSEMBLY.il
SandRock
  • 5,276
  • 3
  • 30
  • 49
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • http://msdn.microsoft.com/en-us/library/xc31ft41(VS.71).aspx MSDN said using:al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk . But I did not succeed – guaike Aug 03 '09 at 06:30
  • 1
    What about keeping the pdb file in sync? – Blake Niemyjski Feb 18 '15 at 03:29
  • If the assembly references another DLL that you are also strongly signing, you get errors stating that it cannot find the unsigned version. Is there a way to update the referenced DLL signatures in the file? – Brain2000 Dec 10 '15 at 04:20
11

Easy way to sign 3rd party assembly is using the GUI version of Assembly Strong Name Signer, available here: http://brutaldev.com/post/2013/10/18/NET-Assembly-Strong-Name-Signer.

It's source code is available on Github. Uses Mono.Cecil for the dirty work. Available also as command line tool.

I have found the recommended ildasm -> ilasm round trip suggested at several places cumbersome and better to be avoided.

I don't know how Assembly Strong Name Signer handles multi-assembly dependencies. In case it does not , the problem and it's solution is described here (published 2008): http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/

xmojmr
  • 8,073
  • 5
  • 31
  • 54
3

Use the Strong Name Tool utility (sn.exe).

Joe Chung
  • 11,955
  • 1
  • 24
  • 33
  • sn.exe can't do this,becacuse sn.exe just can re-sign with storng name assembly – guaike Aug 03 '09 at 03:28
  • I think sn.exe works if the original assembly is marked to be signed later. yes? – Cheeso Aug 03 '09 at 04:46
  • 2
    to Cheeso: Yes,you are right,i found a way:http://ryanfarley.com/blog/archive/2010/04/23/sign-a-.net-assembly-with-a-strong-name-without-recompiling.aspx – guaike Apr 26 '10 at 03:31
3

Take a look at my StrongNameResigner. It can sign or resign an assembly and all assemblies that depend on it while also updating all references using a command like that:

StrongNameResigner.exe -a "c:\temp" -k "key.snk" Foo.Bar
Martin
  • 10,738
  • 14
  • 59
  • 67
  • 1
    Does not work for me. I get an exception: Unable find dependend assemblies: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'myassembly.dll, Culture=.... – codingdave May 25 '18 at 08:57
-4
You can sign the assembly with the help of VS command prompt.
Just type the path in VS cmd prompt where your project is physically present.

In VS cmd
<your project path>sn -k <name of your project>.snk

Then go to your project in Solution Explorer -> properties -> Signing -> check checkbox  
-> Browse to the key which is created using VS cmd.
K T
  • 169
  • 1
  • 4
  • 14