XTLS/Xray-core · error

invalid WireGuard secret key

Error message

invalid WireGuard secret key: %w

What it means

Raised in WireGuardConfig.Build when ParseWireGuardKey fails to interpret the 'secretKey' value — it is neither valid 64-char hex nor decodable base64 key material. The underlying parse error is wrapped.

Solutions

  1. Set secretKey to the WireGuard key in standard base64 or hex form (from 'wg genkey')
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at infra/conf/wireguard.go:77 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/f1b1570b40332511. Report an issue: GitHub.

Appendix: source

Thrown at infra/conf/wireguard.go:77

type WireGuardConfig struct {
	IsClient bool `json:""`

	NoKernelTun    bool                   `json:"noKernelTun"`
	SecretKey      string                 `json:"secretKey"`
	Address        []string               `json:"address"`
	Peers          []*WireGuardPeerConfig `json:"peers"`
	MTU            int32                  `json:"mtu"`
	Reserved       []byte                 `json:"reserved"`
	DomainStrategy string                 `json:"domainStrategy"`
}

func (c *WireGuardConfig) Build() (proto.Message, error) {
	config := new(wireguard.DeviceConfig)

	var err error
	config.SecretKey, err = ParseWireGuardKey(c.SecretKey)
	if err != nil {
		return nil, errors.New("invalid WireGuard secret key: %w", err)
	}

	if c.Address == nil {
		// bogon ips
		config.Endpoint = []string{"10.0.0.1", "fd59:7153:2388:b5fd:0000:0000:0000:0001"}
	} else {
		config.Endpoint = c.Address
	}

	if c.IsClient {
		config.Peers = make([]*wireguard.PeerConfig, len(c.Peers))
		for i, p := range c.Peers {
			msg, err := p.Build()
			if err != nil {
				return nil, err
			}
			config.Peers[i] = msg
		}

View on GitHub (pinned to 7d214f8b09)