AlistGo/alist · error

failed to parse PEM block containing the key

Error message

failed to parse PEM block containing the key

What it means

Loading the stored SFTP RSA host key failed because pem.Decode found no PEM block, meaning the key file is corrupt, empty, or not PEM-encoded.

Solutions

  1. Check the storage configuration and the provider's service status, fix the indicated cause, and retry the operation.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/sftp/hostkey.go:98 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/4eae90ef0abc6063. Report an issue: GitHub.

Appendix: source

Thrown at server/sftp/hostkey.go:98

		return nil, false
	}
	return ret, true
}

func rsaEncodePrivateKey(privateKey *rsa.PrivateKey) []byte {
	privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey)
	privateBlock := &pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   privateKeyBytes,
	}
	return pem.EncodeToMemory(privateBlock)
}

func rsaDecodePrivateKey(bytes []byte) (*rsa.PrivateKey, error) {
	block, _ := pem.Decode(bytes)
	if block == nil {
		return nil, fmt.Errorf("failed to parse PEM block containing the key")
	}
	privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
	if err != nil {
		return nil, err
	}
	return privateKey, nil
}

View on GitHub (pinned to 843d9dc814)