{"record":{"id":"4e08606622d15bb2","repo":"micro/go-micro","slug":"incoming-message-couldn-t-be-verified-decrypted","errorCode":null,"errorMessage":"incoming message couldn't be verified / decrypted","messagePattern":"incoming message couldn't be verified / decrypted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/secrets/box/box.go","lineNumber":85,"sourceCode":"\treturn naclbox.Seal(nonce[:], in, &nonce, &recipientPublicKey, &b.privateKey), nil\n}\n\n// Decrypt Decrypts a message with the receiver's private key and the sender's public key.\nfunc (b *box) Decrypt(in []byte, opts ...secrets.DecryptOption) ([]byte, error) {\n\tvar options secrets.DecryptOptions\n\tfor _, o := range opts {\n\t\to(&options)\n\t}\n\tif len(options.SenderPublicKey) != keyLength {\n\t\treturn []byte{}, errors.New(\"sender's public key bust be provided\")\n\t}\n\tvar nonce [24]byte\n\tvar senderPublicKey [32]byte\n\tcopy(nonce[:], in[:24])\n\tcopy(senderPublicKey[:], options.SenderPublicKey)\n\tdecrypted, ok := naclbox.Open(nil, in[24:], &nonce, &senderPublicKey, &b.privateKey)\n\tif !ok {\n\t\treturn []byte{}, errors.New(\"incoming message couldn't be verified / decrypted\")\n\t}\n\treturn decrypted, nil\n}\n","sourceCodeStart":67,"sourceCodeEnd":89,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/config/secrets/box/box.go#L67-L89","documentation":"NaCl box authentication failed during Decrypt. naclbox.Open verifies the Poly1305 MAC using the derived shared key before decrypting; if verification fails, nothing is returned and this error is thrown. It means the ciphertext, nonce, sender public key, or recipient private key do not form the same key pair used for encryption.","triggerScenarios":"Calling box.Decrypt on ciphertext that was not encrypted with the matching sender private key / recipient public key pair; corrupted or truncated ciphertext (in shorter than 24 bytes + ciphertext, or sliced incorrectly since the first 24 bytes are the nonce); supplying the wrong SenderPublicKey.","commonSituations":"Key rotation where one side still uses an old key; copy-pasting keys with whitespace or wrong encoding; accidentally re-slicing or mutating the encrypted payload before decryption; a sender encrypting with a different curve/key type than box expects.","solutions":["Verify the sender's public key and your private key are the exact complementary pair used at encryption time.","Check that the ciphertext passed to Decrypt is untouched: first 24 bytes nonce, remainder ciphertext; do not trim, prepend, or base64-decode twice.","Re-encrypt with the current keys and retry; if key rotation occurred, distribute the new sender public key to recipients.","Add a checksum/version prefix at the application layer so mismatched keys are detected before naclbox.Open is attempted."],"exampleFix":"// before\nraw, _ := base64.StdEncoding.DecodeString(payload)\ndecrypted, err := b.Decrypt(raw, secrets.WithSenderPublicKey(wrongKey))\n// after\nraw, err := base64.StdEncoding.DecodeString(payload)\nif err != nil { return err }\nif len(raw) < 24 { return errors.New(\"ciphertext too short\") }\ndecrypted, err := b.Decrypt(raw, secrets.WithSenderPublicKey(correctSenderPub))","handlingStrategy":"try-catch","validationCode":"if len(ciphertext) <= 24 {\n    return errors.New(\"ciphertext too short to contain nonce\")\n}","typeGuard":null,"tryCatchPattern":"decrypted, err := b.Decrypt(data, secrets.WithSenderPublicKey(pub))\nif err != nil {\n    if strings.Contains(err.Error(), \"couldn't be verified\") {\n        return fmt.Errorf(\"decryption failed: wrong keys or corrupted data: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep key pairs versioned and distributed together","Transport ciphertext only through lossless encodings (hex/base64)","Never mutate the encrypted payload between encrypt and decrypt","Round-trip test after any key rotation"],"tags":["crypto","nacl-box","decryption","mac-verification"],"backgroundTag":"decryption-authentication-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}