XTLS/Xray-core · error

Unable to marshal private key

Error message

Unable to marshal private key

What it means

Error "Unable to marshal private key" thrown in XTLS/Xray-core.

Source

Thrown at common/protocol/tls/cert/cert.go:178

	if parentCert.NotAfter.Before(template.NotAfter) {
		template.NotAfter = parentCert.NotAfter
	}
	if parentCert.NotBefore.After(template.NotBefore) {
		template.NotBefore = parentCert.NotBefore
	}

	for _, opt := range opts {
		opt(template)
	}

	derBytes, err := x509.CreateCertificate(rand.Reader, template, parentCert, publicKey(selfKey), parentKey)
	if err != nil {
		return nil, errors.New("failed to create certificate").Base(err)
	}

	privateKey, err := x509.MarshalPKCS8PrivateKey(selfKey)
	if err != nil {
		return nil, errors.New("Unable to marshal private key").Base(err)
	}

	return &Certificate{
		Certificate: derBytes,
		PrivateKey:  privateKey,
	}, nil
}

View on GitHub (pinned to 7d214f8b09)

When it happens

Trigger: Thrown at common/protocol/tls/cert/cert.go:178 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/c689e8f1446d8603. Report an issue: GitHub.