April 10, 2025

How do you sign an unsigned assembly, in 2025

How do you sign an unsigned assembly, in 2025

Developers who put their creations on Nuget but do not sign them deserve shaming and lots of. Dudes, it is effortless but saves your users from a lot of headaches. Just do it! Google how and do it! If you don't then here is how anyone can fix their shit for them. Create a CMD file:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\ildasm.exe" /all /typelist /out=%1.il %1.dll /nobar
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ilasm.exe /dll /key=%2.snk %1.il
Its command-line arguments will be the name (without extension) of the original DLL and the name (without extension) of your own SNK file that you will be signing the DLL with.

Example: resign.cmd MyAssembly MyKey

Your next question will be how do you obtain an SNK key if all of your projects are signed with a PFX? Good question! You will have to convert it, keeping the private key in. Microsoft is hell bent on making trouble and causing damage, so sn.exe is unwilling to assist. Programming to the rescue! Create a new command-line project and paste this code into the main method of Program.cs:

var pfxData = File.ReadAllBytes(args[0]);
string password;
if (args.Length > 1)
{
    password = args[1];
}
else
{
    Console.Write("Password: ");
    password = Console.ReadLine();
}

var cert = new X509Certificate2(pfxData, password, X509KeyStorageFlags.Exportable);
var privateKey = (RSACryptoServiceProvider)cert.PrivateKey;

if (args.Length > 2 && (Directory.Exists(args[2]) || Directory.Exists(Path.GetDirectoryName(args[2]))))
{
    File.WriteAllBytes(args[2], privateKey.ExportCspBlob(true));
}
else
{
    File.WriteAllBytes(Path.ChangeExtension(args[0], "snk"), privateKey.ExportCspBlob(true));
}

No fancy async/await shit that you do not need. Build and run it with the PFX file name as the only command-line argument. The output will be the SNK file. Enjoy, and screw the bastards.

Posted by: LinuxLies at 06:36 PM | No Comments | Add Comment
Post contains 281 words, total size 2 kb.




What colour is a green orange?




16kb generated in CPU 0.0146, elapsed 0.0339 seconds.
35 queries taking 0.0215 seconds, 148 records returned.
Powered by Minx 1.1.6c-pink.