Console application in page

  • Thread starter Thread starter Shahid
  • Start date Start date
S

Shahid

I have developed a console application taking into paramters and
outputing an encrypted string.

I am trying to use this program in my php page by using the exec
command. I get the following error:

Unhandled Exception:
System.Security.Cryptography.CryptographicException: CryptoAPI
cryptographic service provider (CSP) for this implementation could not
be acquired. at
System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32
dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) at
System.Security.Cryptography.RSACryptoServiceProvider..ctor() at
Encryption.RSACSPSample.Encrypt(String toEncrypt, String publicKey) at
Encryption.RSACSPSample.Main(String[] args) Content-type: text/html
X-Powered-By: PHP/4.3.4

The odd thing is that once I log into my server and run the page, it
works. Once I log out out of my server and run this page I get the
above error.

The permissions on the exe are set to read/execute for Everyone and
IUSER. I even tried putting the exe in the system32 folder and also
gave full rights.

I have posted this in the PHP groups but I haven't been able to find a
solution.

Any ideas?

Thanks in advance,
Shahid
 
The problem stems from user profile. I say this only because of your
symptoms. Reason is CSP implementations must create Key container in order
to store RSA assymetric keys. These containers are be stored in User
Profile. In ASP.NET page, as in some other instances, user profile is not
loaded. If my memory is correct, I think this is for performance reasons.
In any case, when no user profile is present, the key container can not be
created. However once you are to log in, then the container can be created
because a profile can be loaded and that's why problem no longer shows
itself.

To fix you need to tell Provider , RSA orDSA to use Machine key store. The
solution for which is too long to write out here, but in MSDN site, look up
article 322371 and it has code for full resolution and better explanation.
 
Back
Top