Fix Visual Studio Code Signing: Cannot import the following key file, the key file may be password protected

When importing a signing key to sign your assembly, you may get the error “cannot import the following key file the key file may be password protected”- here’s a fix

The Problem:

Exact error:

Error: Cannot import the following key file: signing2.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_85FC6297243186A2 BrwCacheSpeedMultiplier

The Solution

1. Step Make sure you have correctly imported the key into your Personal Certificate folder

2. Step After you’ve done that, export the key you just imported to a file e.g. company.pfx

Solution 1) Use OpenSSL on VirtualBox Ubuntu

3. Step Install Virtual Box

4. Step Get Ubuntu and install it as a Virtual Machine

5. Step In the settings, make sure to add a Shared folder to e.g. D:\SERVER

6. Step Now boot Ubuntu and enter df -h to check your mounts. You should see a mount labelled SERVER

Your Shared Folder.png

7. Step If you dont see it, restart the virtual machine, make sure the path to the shared folder actually exists or it wont be able to auto-mount it

8. Step Ok, now copy the company.pfx to the shared folder

9. Step Open the terminal on Ubuntu and enter cd /media/sf_SERVER (your shared folder may be called differently!, use df -h)

10. Step Now run this and replace company.pfx with your own pfx file in the first line. Then in the 2nd line dont replace anything, just run it and it will create a companyWORKING.pfx file

openssl pkcs12 -in company.pfx -out backup.key

openssl pkcs12 -export -out companyWORKING.pfx -keysig -in backup.key

11. Ok, you are done

12. Go back to Visual Studio and import your pfx

Sign The Assembly.png

13. Enter the password when asked

You can now build the project and it will work. Wow! Kudos to Microsoft for making it so difficult to sign an assembly – something that should be as easy as 1,2,3 nowadays

Alternative Approach SN.exe (Did NOT Work For Me!)

Cannot Import The Following Key File May Be Password Protected.png
Pic: cannot import the following key file the key file may be password protected

1. Step Open up C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools

2. Step Open a command prompt

3. Step Enter cd C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools

4. Step Enter sn -d VS_KEY_85FC6297243186A2

5. Step Enter sn -i D:\1 SIGN KEY\my-sign-key.pfx VS_KEY_xxxxxxxxxxxx

Published: Thursday, December 12th, 2013 Last Modified: December 12, 2013

Related Posts

Rate This Article
5 of 5 0 (100%) 1 vote