{"record":{"id":"47ab0e3c6a923c4c","repo":"slackhq/nebula","slug":"key-was-not-d-bytes-is-invalid-ed25519-private-k","errorCode":null,"errorMessage":"key was not %d bytes, is invalid ed25519 private key","messagePattern":"key was not (.+?) bytes, is invalid ed25519 private key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cert/crypto.go","lineNumber":291,"sourceCode":"\tif err != nil {\n\t\treturn curve, nil, r, err\n\t}\n\n\tvar bytes []byte\n\tswitch ned.EncryptionMetadata.EncryptionAlgorithm {\n\tcase \"AES-256-GCM\":\n\t\tbytes, err = aes256Decrypt(passphrase, &ned.EncryptionMetadata.Argon2Parameters, ned.Ciphertext)\n\t\tif err != nil {\n\t\t\treturn curve, nil, r, err\n\t\t}\n\tdefault:\n\t\treturn curve, nil, r, fmt.Errorf(\"unsupported encryption algorithm: %s\", ned.EncryptionMetadata.EncryptionAlgorithm)\n\t}\n\n\tswitch curve {\n\tcase Curve_CURVE25519:\n\t\tif len(bytes) != ed25519.PrivateKeySize {\n\t\t\treturn curve, nil, r, fmt.Errorf(\"key was not %d bytes, is invalid ed25519 private key\", ed25519.PrivateKeySize)\n\t\t}\n\tcase Curve_P256:\n\t\tif len(bytes) != 32 {\n\t\t\treturn curve, nil, r, fmt.Errorf(\"key was not 32 bytes, is invalid ECDSA P256 private key\")\n\t\t}\n\t}\n\n\treturn curve, bytes, r, nil\n}\n","sourceCodeStart":273,"sourceCodeEnd":301,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cert/crypto.go#L273-L301","documentation":"After decrypting the payload for a Curve_CURVE25519 (Ed25519) key, the library validates that the plaintext is exactly ed25519.PrivateKeySize (64) bytes. If decryption yielded the wrong length, the plaintext cannot be a valid Ed25519 private key and this error is returned.","triggerScenarios":"DecryptAndUnmarshalSigningPrivateKey with an Ed25519 banner whose decrypted ciphertext is not 64 bytes — caused by a wrong passphrase producing garbage (though AEAD should usually fail first), a truncated/corrupted key file, or ciphertext that was re-encrypted from wrong-length plaintext.","commonSituations":"Truncated key files from bad transfer/storage, corrupted ciphertext, or mismatched key material produced by buggy tooling.","solutions":["Re-obtain or re-copy the encrypted key file — it is likely truncated or corrupted","If a wrong passphrase is involved, verify the passphrase; though AEAD auth normally fails earlier, validate the source key","Regenerate the signing key with nebula-cert and re-sign affected certificates"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"curve, key, rest, err := cert.DecryptAndUnmarshalSigningPrivateKey(pass, b)\nif err != nil {\n\tif strings.Contains(err.Error(), \"invalid ed25519 private key\") {\n\t\treturn fmt.Errorf(\"decrypted Ed25519 key has wrong length; key file is corrupt or truncated, restore from backup: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Store key files with checksums and verify on load","Use atomic file writes when generating or updating keys","Keep a backup of signing keys; a wrong-length plaintext means the file is damaged"],"tags":["ed25519","key-length","key-management","go"],"backgroundTag":"invalid-private-key-length","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}