System.Security.Cryptography.CryptographicException: The system cannot find the file specified.

Discussion in 'ASP.NET WebServices' started by Loki117, May 14, 2008.

  1. Anyone seen this error when attempting to use a key to encrypt data from a webservice? The error is driving me up the wall I can't get it to work even though I am using an absolute reference to the keyfiles in my web.config. Does any users need specific access to a key?

    Thanks,

    Tom
     
  2. Hi rcp thanks very much it sounds feasible but I can't change the code which constructs the encryption as it is within a 3rd party DLL. I am not actually using a keystore anyway I just placed the certs in a directory and point the DLL at them do they need to be installed one is a pfx the other is a cer.


    Tom
     
  3. As I understand it, the application uses some keystore for temporary storagewhen working with certificates. So the component will need to specify the machine's keystore instead of the default user keystore. Unfortunately, this is the only way to get it to work.

    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. Ok umfortunatly as the component I am using is 3rd party I can't use the machine key store for the cert is there no other way to get this working?

    I have seen other people having no issue directly referencing a cert in there local directory on other hosting enviroments it's something which would actually stop me from using this hosting as I dont want to pay to have the cert installed in the machine store try and find the thumb print and then find out it still doesnt work due to some config issue with IIS or the ASP.Net wp :( it's becoming a real show stopper.
     
  5. Aristotle:

    I am facing the same issue that Loki reported.

    I am using the example that comes with the RSACryptoServiceProvider documentation


    Sub RSAPersistKeyInCSP(ByVal ContainerName As String)
    Try
    ' Create a new instance of CspParameters. Pass
    ' 13 to specify a DSA container or 1 to specify
    ' an RSA container. The default is 1.
    Dim cspParams As New CspParameters

    ' Specify the container name using the passed variable.
    cspParams.KeyContainerName = ContainerName

    'Create a new instance of RSACryptoServiceProvider to generate
    'a new key pair. Pass the CspParameters class to persist the
    'key in the container.
    Dim RSAalg As New RSACryptoServiceProvider(cspParams) '<---------------------------------------------This line generates the error

    'Indicate that the key was persisted.
    Console.WriteLine("The RSA key was persisted in the container, ""{0}"".", ContainerName)
    Catch e As CryptographicException
    Console.WriteLine(e.Message)
    End Try
    End Sub


    Could you please tell me how to specify the machine storage?


    Thank you.
     
  6. Bruce

    Bruce DiscountASP.NET Staff

    You can use something like the following.





    CspParameters cspParams;
    cspParams = new CspParameters(1);
    cspParams.KeyContainerName= "MyContainer";
    cspParams.Flags =CspProviderFlags.UseMachineKeyStore;
    RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider(cspParams);


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     

Share This Page