System.Security.Cryptography.CryptographicException: keyset does not exist

前端 未结 8 1445
时光取名叫无心
时光取名叫无心 2020-12-04 09:59

When I make x509 certificate to encypt and decypt message, I got some error information and could not fix this problem. Could someone ever happend to solve this bug? thanks.

相关标签:
8条回答
  • 2020-12-04 10:59

    I believe when using Encrypt and Decrypt it expects a public key for encrypt and a private key for decrypt. So it is failing because you are trying to decrypt without the private key and that causes the exception.

    You should really be using SignData method for creating the signature and VerifyData for the verification.

    0 讨论(0)
  • 2020-12-04 11:01

    This question is old but for someone looking for the solution while continuing to use Encrypt and Decrypt here is how I manage to solve this error:

    The base is my certificate have been installed the wrong way by double-clicking the .pfx file and selecting the store.

    The wrong way to install the certificate

    1. Double click the certificate:

    certificate file

    2. The wizard opens, click in the next button:

    wizard 0

    3. The wizard show the certificates location, click in the next button:

    wizard 1

    4. Enter the password then click next:

    wizard 2

    5. Select the store then click next:

    wizard 3

    6. The wizard show the certificate information, click in Finish button

    wizard 4

    7. Succes dialog is showed:

    wizard 5

    So at this point I had the error "Keyset does not exist".


    To solve that I proceeded this way (the correct way)

    1. Execute Microsoft Management Console (mmc.exe):

    execute mmc

    2. A blank MMC instance showed:

    mmc showed

    3. Click in File->Add/Remove Snap-in...

    add snap-in

    4. Select certificate snap-in an click in Add button:

    add certificate snap-in

    5. Select Computer account then click in Next button:

    select computer account

    6. Select Local computer then click in Finish button:

    selecct local computer

    7. The certificate snap-in is now added, click in OK button:

    certificate snap-in shows

    8. Select the personal store, then right click and select Import:

    select personal store and import

    9. Browse the certificate, and click next:

    browse certificate

    10. Enter the password, then click in Next button:

    enter image description here

    11. Automatically select the certificate store:

    automatically select the store

    12. The certificate information shows:

    certificate information

    13. Success dialog message shows:

    enter image description here

    14. Refresh the MMConsole to show the certificate:

    refresh mmc

    15. Right click on the certificate, then click in Manage Private Keys...:

    manage private keys

    16. Add the pool identity or the IIS user in my case I added IIS_IUSRS:

    add iis_iusrs

    17. The user has been added, click on OK button:

    user added

    And it is finished the keyset does exist now!!

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