0

I created a web service that receives a .p12 file as a Byte Array and parses it as X509Certificate, when I tested it locally it worked just fine, but when I deployed it I'm getting the following error when trying to create the X509Certificate:

The system cannot find the file specified.

The code

//cerBytes is a Byte[] and passCert is a String
X509Certificate2 cert = new X509Certificate2(certBytes, passCert);

As I read, the problem is that it's trying to read the Certificate from the actual server, which is not the behaviour I'm looking for, I just need to parse the certificate from the Byte Array (that come from different senders/customers) sign an XML and that's it, There's no need to store the Certificate in the server.

Is there anyway to accomplish what I'm looking for?

  • Can you let us see your web service code and how do you convert the received file into a byte array. – RaniDevpr Dec 31 '17 at 11:11
  • Rani, that’s the actual Code, the X509Certificate constructor accepts the byte array and the password of the p12 file. It also has another one when instead of the byte array receives a file path, but since this is executed via web service. The path will never be valid. – Melvin Hidalgo Aguilar Dec 31 '17 at 11:25
  • 1
    Possible duplicate of [What exactly happens when I set LoadUserProfile of IIS pool?](https://stackoverflow.com/questions/17149132/what-exactly-happens-when-i-set-loaduserprofile-of-iis-pool) – rene Dec 31 '17 at 12:24
  • Thanks Rene, the thing is that the hosting that I’m using won’t let me configure stuff on IIS, everything is deployed as a web application (gear host) – Melvin Hidalgo Aguilar Dec 31 '17 at 18:28

1 Answers1

0

You should take a look on BinaryFormatter class , on client side, create the X509Certificate2 object, once serialized and sent, create a new MemoryStream with given byte array and deserialize it as X509Certificate2 on server side, hope this helps :)