{"record":{"id":"c689e8f1446d8603","repo":"XTLS/Xray-core","slug":"unable-to-marshal-private-key","errorCode":null,"errorMessage":"Unable to marshal private key","messagePattern":"Unable to marshal private key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/protocol/tls/cert/cert.go","lineNumber":178,"sourceCode":"\tif parentCert.NotAfter.Before(template.NotAfter) {\n\t\ttemplate.NotAfter = parentCert.NotAfter\n\t}\n\tif parentCert.NotBefore.After(template.NotBefore) {\n\t\ttemplate.NotBefore = parentCert.NotBefore\n\t}\n\n\tfor _, opt := range opts {\n\t\topt(template)\n\t}\n\n\tderBytes, err := x509.CreateCertificate(rand.Reader, template, parentCert, publicKey(selfKey), parentKey)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to create certificate\").Base(err)\n\t}\n\n\tprivateKey, err := x509.MarshalPKCS8PrivateKey(selfKey)\n\tif err != nil {\n\t\treturn nil, errors.New(\"Unable to marshal private key\").Base(err)\n\t}\n\n\treturn &Certificate{\n\t\tCertificate: derBytes,\n\t\tPrivateKey:  privateKey,\n\t}, nil\n}\n","sourceCodeStart":160,"sourceCodeEnd":186,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/protocol/tls/cert/cert.go#L160-L186","documentation":"Raised in cert Generate when x509.MarshalPKCS8PrivateKey fails to serialize the freshly generated ECDSA key — a Go crypto-layer failure on a valid key; practically unreachable for supported key types.","triggerScenarios":"Thrown at common/protocol/tls/cert/cert.go:178 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Should not occur for ECDSA keys; report as a bug if seen"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","contentChangedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}