The following error may occur when building projects for Microsoft Visual Studio 2008 - 2015.
Error: "Cannot import the following key file: mykey.pfx. The key file may be password protected."
Cannot import the following key file: mykey.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_C1D3ACB8FBF1AGK4
- Click Start > All Programs > Microsoft Visual Studio >Visual Studio Tools > Visual Studio Command Prompt.
Type the following command
sn -i "c:\Pathtofile\.pfx" VS_KEY_C1D3ACB8FBF1AGK4
- Note: The sn.exe with the -i parameter, installs a key pair from into a key container named.
- Re-import the PFX file into Visual Studio.
- Click on the Signing section.
- Where it says ‘Choose a strong name key file:’, re-select the current value from the drop-down box
- Visual Studio will now prompt you for the password. Enter it.
- You might get another error message:
”An attempt was made to reference a token that does not exist” > You can simply ignore this message.
- Click the ‘Change Password” button
- Enter the original password in all three boxes and click OK. If you’d like to change your password (or if your old password doesn’t meet complexity requirements), you can do so now.
- Repeat for each key file in your project.
- Save your project and do a rebuild.
- Get a copy of openssl for windows at slproweb.com or use a Linux box as they all pretty much have it.
- Run the following to export to a key file
> openssl pkcs12 -in certfile.pfx -out backupcertfile.key
> openssl pkcs12 -export -out certfiletosignwith.pfx -keysig -in backupcertfile.key
- Then in the project properties you can use the PFX file
The final solution for this issue is to give up on Visual Studio for signing purpose and use "Signtool" instead. Check the related articles section for more information regarding this.