Visual Studio 2010 Assembly Signing: An attempt was made to reference a token that does not exist

前端 未结 4 516
有刺的猬
有刺的猬 2021-02-05 07:11

I\'m trying to sign an assembly in Visual Studio 2010 with our PFX file, after I enter the password for the private key I get "An attempt was made to reference a token that

相关标签:
4条回答
  • 2021-02-05 07:32

    If you want Visual Studio to automatically sign the files and work with ClickOnce, this is what I had to do:

    • Get a copy of OpenSSL. It is available for Windows. Or use a Linux box as they all pretty much all 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.

    0 讨论(0)
  • 2021-02-05 07:40

    This is what worked for me.

    First try to build your project with the Key signing option enabled for your project. The build will fail, goto the 'Output' window and you'll see an error like:

    Error 1 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_7B9423FE45F4DBEB Project.SomeName

    Save the Key Store name (e.g. VS_KEY_7B9423FE45F4DBEB), you will need this later.

    Now follow these steps:

    1. Import the digital certificate key (PFX) in the Windows Certificate Store. Double click the PFX key in Windows Explorer and install/import it into your key store (I actually imported it into the trusted root certificates store by selecting manually choose store).
    2. Start Visual Studio 2010 as regular user (I don't face this key signing issue as an Administrator, but I want to debug my apps as a user) (keep it open through this entire process)
    3. From the Start Menu open the Visual Studio Command Prompt (2010) shortcut (x64 if you on a x64 machine) AS AN ADMINISTRATOR (right click on the Visual Studio 2010 Command Prompt shortcut and select run as Administrator). This should open an administrative command prompt with the Visual Studio environment setup. (not a regular command prompt)
    4. In the command prompt, enter sn -d VS_KEY_xxxx with Key Store name from error message you saved at the beginning
    5. Then enter sn -i xxx.pfx VS_KEY_xxxx, enter password when prompted, xxx.pfx if your digital certificate
    6. Go back to Visual Studio and rebuild your project
    0 讨论(0)
  • 2021-02-05 07:45

    Running Visual Studio as Administrator fixed this issue for me.

    0 讨论(0)
  • 2021-02-05 07:53

    I have the same problem. Just use signtool from the Visual Studio command prompt instead. Sometimes signtool will claim your password is invalid, but usually after a couple of tries it starts working for me.

    signtool.exe sign /f YOURCERT.pfx /p YOURPASSWORD YOURTARGET.exe

    0 讨论(0)
提交回复
热议问题