Fix cert export: use PFX instead of PEM for .NET Framework compat

ExportPkcs8PrivateKey() is only available in .NET Core 3.0+
but Windows PowerShell 5.1 uses .NET Framework 4.x.
Switch to PFX export which works on all Windows versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 10:02:27 +02:00
parent 60b44788fd
commit 69b3c417f1
2 changed files with 18 additions and 24 deletions
+8 -6
View File
@@ -102,18 +102,20 @@ function handleRequest(req, res) {
}
// Zertifikate laden und HTTPS-Server starten
const certFile = path.join(CERT_DIR, "localhost.crt");
const keyFile = path.join(CERT_DIR, "localhost.key");
const pfxFile = path.join(CERT_DIR, "localhost.pfx");
const pfxPasswordFile = path.join(CERT_DIR, "pfx-password.txt");
if (!fs.existsSync(certFile) || !fs.existsSync(keyFile)) {
if (!fs.existsSync(pfxFile) || !fs.existsSync(pfxPasswordFile)) {
console.error("Zertifikate nicht gefunden in:", CERT_DIR);
console.error("Bitte zuerst setup.ps1 ausführen.");
console.error("Bitte zuerst setup.ps1 ausfuehren.");
process.exit(1);
}
const pfxPassword = fs.readFileSync(pfxPasswordFile, "utf-8").trim();
const serverOptions = {
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
pfx: fs.readFileSync(pfxFile),
passphrase: pfxPassword,
};
const server = https.createServer(serverOptions, handleRequest);