{"record":{"id":"8301d76df28e8909","repo":"sipeed/picoclaw","slug":"invalid-aes-key-length-d","errorCode":null,"errorMessage":"invalid AES key length %d","messagePattern":"invalid AES key length (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/channels/wecom/media.go","lineNumber":99,"sourceCode":"\t\t}\n\t}\n\treturn body\n}\n\nfunc decodeMediaAESKey(value string) ([]byte, error) {\n\tif value == \"\" {\n\t\treturn nil, nil\n\t}\n\tkey, err := base64.StdEncoding.DecodeString(value)\n\tif err == nil && len(key) == 32 {\n\t\treturn key, nil\n\t}\n\tkey, err = base64.StdEncoding.DecodeString(value + \"=\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"decode AES key: %w\", err)\n\t}\n\tif len(key) != 32 {\n\t\treturn nil, fmt.Errorf(\"invalid AES key length %d\", len(key))\n\t}\n\treturn key, nil\n}\n\nfunc decryptAESCBC(key, ciphertext []byte) ([]byte, error) {\n\tif len(ciphertext) == 0 {\n\t\treturn nil, fmt.Errorf(\"ciphertext is empty\")\n\t}\n\tif len(ciphertext)%aes.BlockSize != 0 {\n\t\treturn nil, fmt.Errorf(\"ciphertext length %d is not a multiple of block size\", len(ciphertext))\n\t}\n\tblock, err := aes.NewCipher(key)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create cipher: %w\", err)\n\t}\n\tplaintext := make([]byte, len(ciphertext))\n\tiv := key[:aes.BlockSize]\n\tcipher.NewCBCDecrypter(block, iv).CryptBlocks(plaintext, ciphertext)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/wecom/media.go#L81-L117","documentation":"Guard in decodeMediaAESKey: the value decoded from base64 successfully (after padding fix-up) but its byte length is not 32. WeCom media decryption requires an AES-256 key, so any other length is rejected before decryption is attempted.","triggerScenarios":"Thrown at pkg/channels/wecom/media.go:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate the EncodingAESKey in the WeCom admin console so it decodes to exactly 32 bytes (standard 43-character key)","Check for accidental extra or missing characters that shift the decoded length"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","contentChangedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}