{"record":{"id":"f71b5e5345bb0426","repo":"slackhq/nebula","slug":"key-was-not-32-bytes-is-invalid-ecdsa-p256-privat","errorCode":null,"errorMessage":"key was not 32 bytes, is invalid ECDSA P256 private key","messagePattern":"key was not 32 bytes, is invalid ECDSA P256 private key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cert/crypto.go","lineNumber":295,"sourceCode":"\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":277,"sourceCodeEnd":301,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cert/crypto.go#L277-L301","documentation":"For a Curve_P256 key, the decrypted plaintext must be exactly 32 bytes (an ECDSA P256 private scalar). This error is returned when the decrypted payload length differs, meaning the plaintext is not a valid P256 private key.","triggerScenarios":"DecryptAndUnmarshalSigningPrivateKey with an EncryptedECDSAP256PrivateKeyBanner whose decrypted ciphertext is not 32 bytes — truncated or corrupted key file, corrupted ciphertext, or wrong data encrypted under the P256 banner.","commonSituations":"Key files damaged in transfer, partial writes to disk, or tooling that encrypted wrong-length material under an ECDSA banner.","solutions":["Re-obtain or re-copy the encrypted key file — it is likely truncated or corrupted","Verify the key was created as an ECDSA P256 key with correct 32-byte scalar material","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 ECDSA P256 private key\") {\n\t\treturn fmt.Errorf(\"decrypted P256 key is not 32 bytes; 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":["ecdsa","p256","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"}