I need to create post build event to perform the following:
sn -i MyKey.pfx MyKeyContainerName
tlbimp $(ConfigurationName)\MyCom.tlb /out:$(ConfigurationName)\NETMyCom.dll /keycontainer:MyKeyContainerName
sn -d MyKeyContainerName
When the Visual Studio executes the 1st statement it requires a password and waits until the user specifies it and fails.
Microsoft (R) .NET Framework Strong Name Utility Version 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved.
Enter the password for the PKCS#12 key file: Failed to parse the PKCS#12 blob in mykey.pfx -- The handle is invalid.
I tried to specify the password using sn command line arguments, but I could not see a way to do it.
Please help.
Regards, Hilmi.
The Strong Name tool (Sn.exe) helps sign assemblies with strong names. Sn.exe provides options for key management, signature generation, and signature verification. Do not rely on strong names for security. They provide a unique identity only.
It is named “sn.exe” so the full path is “C:\Program Files (x86)\Microsoft SDKs\Windows\v10. 0A\bin\NETFX 4.6. 1 Tools\sn.exe”.
Or directly through Microsoft Visual Studio IDE via project's properties – click on signing tab, check “Sign the assembly” then browse to the . snk file: By building your project, you get a strong name signed assembly.
In Visual Studio Solution Explorer, right-click the project and then click Properties. Click the Signing tab and choose Browse in the Choose a strong name key file drop down box. Browse to the key file and click it. Click Open, and then close the project properties.
After a long investigation i can run sn.ex for various automated environments such as Azure devops. My code is here:
Start-Process cmd.exe
Sleep 3
$WshShell = New-Object -ComObject WScript.Shell
Sleep 3
$WshShell.sendkeys(".\sn.exe -i $PfxCertificatePath VS_KEY_10D1C85C6387479B{Enter}");
Sleep 3;
$WshShell.sendkeys("**password**{Enter}");
Sleep 3;
$WshShell.sendkeys("{Enter}");
Unfortunately, no approached mentioned here worked for me. I have to register couple pfxs in a docker container.
So I re-developed the
sn.exe -i <infile> <container>
command in C# using the RSACryptoServiceProvider. The source and the app are on GitHub in
the SnInstallPfx project.
The SnInstallPfx app accepts a PFX key and its password. It computes the key container name (VS_KEY_*) automatically (borrowed from MSBuild source code) and installs it to the strong name CSP.
Usage:
SnInstallPfx.exe <pfx_infile> <pfx_password>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With