Preamble:
I want to create an X509Certificate or X509Certificate2 to be used in an SslStream lifecycle (i.e. to secure my connection)... in a Unity game. Unity, in 2020.3 version projects, only supports .NET Standard 2.0 / .NET Framework 4.x series.
Notes:
In .NET 6, I have this method or this one.
In .NET 5, I have the "import" methods in the RSA class, depending on the PEM header.
Also in .NET 5 there is a method like CopyWithPrivateKey to build a certificate with its private key. In .NET Standard I have to stick to doing .PrivateKey = (an asymmetric alg).
So while I might seem to be able to create a certificate (I load it by manually parsing PEM) I don't know how to load the private key since those methods are not supported in .NET Standard 2.0.
Problem: I am using .NET Standard 2.0 since this is Unity, and I'm creating a server (yes: in Unity as well) supporting SSL.
So my Question is: How can I take two pem files (key and certificate) and instantiate a X509Certificate or X509Certificate2 in .NET Standard 2.0? Considering the files are created like this:
openssl req -x509 -newkey rsa:2048 -keyout server-key.pem -out server-cert.pem -sha256 -days 365
with a passphrase I enter later!!!
Also considering my server will not necessarily run in Windows.
An accepted answer should include either some snippet or a link to a 3rd party library or polyfill. I'm really stuck with this and I cannot move from .NET Standard 2.0.