System.Security.Cryptography.CryptographicException: Cryptography_CSP_NoPrivateKey

Steps:
1. Open IIS
2. Click on Application Pools
3. Select respective application pool and click on "Advanced Settings..." 
4.  Set Identity value as "NetworkService"


5. Click on Ok
6. Provide "Read and Execute" access to the application path for "Network Service" user.
7. Download and build code to generate "FindPrivateKey.exe" from the url https://www.microsoft.com/en-us/download/details.aspx?id=21459 and refer https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/findprivatekey?redirectedfrom=MSDN
8.  Open "Manage user certificates" and expand "Personal" and "Certificates" and open the installed certificate.
9. In Details tab, click on "Thumbprint" property and copy its value.
10. Open code folder (i.e downloaded and builded in step 7) on the open command prompt and run the command as FindPrivateKey.exe My LocalMachine -t "d8519196d4445a1355db3d0062e0ab489b93a932"

Refer:
C:\WF_WCF_Samples\WCF\Setup\FindPrivateKey\CS\obj\Debug>FindPrivateKey.exe My LocalMachine -t "d8519196d4445a1355db3d0062e0ab489b93a932"
Private key directory:
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
Private key file name:
3f3278c248d4898e792c662dca37d4ca_6cc3a1b9-8f47-47fa-e5bd735cec7d


11. Now open the path "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys" and choose the file "3f3278c248d4898e792c662dca37d4ca_6cc3a1b9-8f47-47fa-e5bd735cec7d" (which is shown is command prompt)
12. Right click the file, open properties, and "Security" then provide "Read & Execute" access to this file for "Network Service" user.

Now run the application, The NoPrivateKey error is fixed.


No comments:

Post a Comment