0

I have a root chain and certificate stored in a single .p7b file that I'd like to authenticate/bind to a Unity environment. I came across Unity's CertificateHandler class https://docs.unity3d.com/ScriptReference/Networking.CertificateHandler.html and Microsoft's X509Certificates. Using X509Certificate I'd like to validate my certificate like so:

    byte[] content = File.ReadAllBytes("servercerts.p7b");
    string contentString = Convert.ToBase64String(content);
    X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(contentString), string.Empty);

The Console output in Unity returns the message: CryptographicException: Input data cannot be coded as a valid certificate. I have seen related issues where people have swapped out different parameters for X509Certificate2() though that type of solution has not been helpful in my case.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
eliboy8
  • 33
  • 1
  • 6
  • Does this answer your question? ['Cannot find the requested object' exception while creating X509Certificate2 from string](https://stackoverflow.com/questions/44053426/cannot-find-the-requested-object-exception-while-creating-x509certificate2-fro) – Charlieface Mar 30 '23 at 19:47
  • If you want to read a P7B as a collection, either use X509Certificate2Collection.Import, or send it to SignedCms.Decode and iterate over the certificates collection on the SignedCms object. Sending a p7b to the X509Certificate2 constructor does... different things :) – bartonjs Mar 31 '23 at 17:40
  • @Charlieface Thanks though I've tried importing the P7B into a X509Certificate2Collection object but receive the same exception from above – eliboy8 Apr 01 '23 at 18:13

0 Answers0