Generando certificado autofirmado sin bibliotecas externas

Tengo curiosidad por saber si hay una manera simple de crear un certificado autofirmado comparable al siguienteNew-SelfSignedCertificate comando (otros proveedores también están bien, por ejemplo). Quiero usar solo las bibliotecas .NET sin P / Invoke o bibliotecas externas como Bouncy Castle o sin llamar a PowerShell desde la aplicación.

New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation $certificateStore -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $certificateNotAfter

Supongo que la alternativa más simple sería llamar a PowerShell o usar una biblioteca Nuget como Bouncy Castle, si esto no es posible sin instalaciones externas. Aunque parece que si supiera lo suficiente cómo construir certificados, sería posible crear una plantilla de matriz de bytes o algo así y usarla en elX509Certificate2 constructor.

Parece que uno necesitaría

public X509Certificate2 GenerateCertificate(string fileName, string password, string subjectName, StoreName storeName, DateTime endDate, DateTime notAfter, string provider = "Microsoft Enhanced RSA and AES Cryptographic Provider")
{
    //Could provider be taken from https://stackoverflow.com/questions/43474902/generate-self-signed-rsa-2048-sha-256-certificate-pfx-file-using-openssl?            
    var newCertificate = new X509Certificate2(fileName, password, X509KeyStorageFlags.Exportable);

     /*
      # The following creates a self-signed certificate with one year of running time.
     $currentDate = Get-Date
     $certificateEndDate = $currentDate.AddYears(1)
     $certificateNotAfter = $certificateEndDate.AddYears(1)

     $certificateName = "https://www.test.com/test"
     $certificateStore = "Cert:\LocalMachine\My"
     New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation $certificateStore -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $certificateNotAfter
     */
}

<editar: Rápidamente se hizo evidente que no hay una buena manera de hacer esto con .NET.

Algunas opciones más que encontré:

Una publicación de blogCreación de certificados firmados por la autoridad y autofirmados en .NET porSteve Syfuhs y otra publicación SO usando extensiones Mono,Mono.Security no configurará múltiples KeyUsages. Además de las opciones ya discutidas, es "algo como esto".

Respuestas a la pregunta(1)

Su respuesta a la pregunta