Cryptographicexception Was Unhandled: System Cannot Find the Specified File

CryptographicException was unhandled: System cannot find the specified file

Did you set the following on the application pool in IIS?

  1. Go to IIS Manager
  2. Go to the application pool instance
  3. Click advanced settings
  4. Under Process model, set Load User Profile to true

See this stack question for further reading: What exactly happens when I set LoadUserProfile of IIS pool?

X509Certificate2 Error - System cannot find the file specified

Providing an Absolute path, rather than a Relative path did help. The intention of providing a relative path was to include the certificate as part of the artifacts, and when the application gets deployed to the server, the certificate would get written to the output path, and get read from the location.
However, while trying to test the working code, and currently, I find that only the absolute path is working, although the certificate property is set to copy always. The working code now looks like this :

filePath = @"C:\Users\<user name>\Documents\TestCompany-qa.partner.client.siriusxm.com.pfx"; 

X509Certificate2 certificate = new X509Certificate2(filePath, "****key****");

So, need to know the path in the server where the application is deployed and the certificate location, to proceed now, as the workaround solution.

CngKey System.Security.Cryptography.CryptographicException The system cannot find the file specified on Azure

I upgraded the plan service from free to basic with adding WEBSITE_LOAD_USER_PROFILE = 1 in Azure Configuration.

The issue was when the app service was free it use a shared VM but when upgrading my app service pricing into basic it use a private VM.

HTTP Error 500.30 (Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.)

I after searching for this error and googling, this solution worked for me. IIS Manager->application pool -> advanced settings ->Under Process model, Load User Profile to true. More detail on link

The system cannot find the file specified - azure key vault certificat

Reading PFX requires the user profile to be loaded. When we added WEBSITE_LOAD_CERTIFICATES, it basically results in loading the profile on the background and hence we could read the PFX from the filesystem.

ASP.NET and ASP.NET Core on Windows must access the certificate store even if you load a certificate from a file. To load a certificate file in a Windows .NET app, add WEBSITE_LOAD_USER_PROFILE=1 option into the application's settings.

For more details, you could refer to this article.

RSACryptoServiceProvider CryptographicException System Cannot Find the File Specified under ASP.NET

Indeed you need to work a code like this

CspParameters _cpsParameter;
RSACryptoServiceProvider RSAProvider;

_cpsParameter = new CspParameters();
_cpsParameter.Flags = CspProviderFlags.UseMachineKeyStore;

RSAProvider = new RSACryptoServiceProvider(1024, _cpsParameter);

The following users need access to the folder: C:\Documents and Settings\All Users\Application data\Microsoft\Crypto\RSA\MachineKeys

  1. IIS user account (anonymmous)
  2. The user account you use to impersonate your application in the web.config settings.

So now it is working fine for me.



Related Topics



Leave a reply



Submit