private Certificate CreateCert(string hostName, string traefikCertsPath) { var certsPath = Path.Combine(traefikCertsPath, $"{hostName}"); var certKeyPath = $"{certsPath}.key"; var certPath = $"{certsPath}.crt"; var certificate = new Certificate { CertFile = $@"C:\etc\traefik\certs\{hostName}.crt", KeyFile = $@"C:\etc\traefik\certs\{hostName}.key" }; if (File.Exists(certificate.CertFile)) { return(certificate); } var baseDirectory = AppContext.BaseDirectory; var dimmyCert = Path.Combine(baseDirectory, "dimmy.pfx"); var x509 = new X509Certificate2(dimmyCert); var cert = _certificateService.CreateSignedCertificate(hostName, hostName, x509); File.WriteAllText(certKeyPath, _certificateService.CreateKeyString(cert)); File.WriteAllText(certPath, _certificateService.CreateCertificateString(cert)); return(certificate); }