{"record":{"id":"709a36a4eb898b47","repo":"chenhg5/cc-connect","slug":"encodingaeskey-must-be-43-characters-got-d","errorCode":null,"errorMessage":"EncodingAESKey must be 43 characters, got %d","messagePattern":"EncodingAESKey must be 43 characters, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":740,"sourceCode":"\treturn nil\n}\n\n// --- Crypto helpers ---\n\n// verifySignature checks SHA1(sort(token, timestamp, nonce, encrypt)).\nfunc (p *Platform) verifySignature(expected, timestamp, nonce, encrypt string) bool {\n\tparts := []string{p.token, timestamp, nonce, encrypt}\n\tsort.Strings(parts)\n\th := sha1.New()\n\th.Write([]byte(strings.Join(parts, \"\")))\n\tgot := fmt.Sprintf(\"%x\", h.Sum(nil))\n\treturn got == expected\n}\n\n// decodeAESKey converts the 43-char Base64 EncodingAESKey to 32 bytes.\nfunc decodeAESKey(encodingAESKey string) ([]byte, error) {\n\tif len(encodingAESKey) != 43 {\n\t\treturn nil, fmt.Errorf(\"EncodingAESKey must be 43 characters, got %d\", len(encodingAESKey))\n\t}\n\treturn base64.StdEncoding.DecodeString(encodingAESKey + \"=\")\n}\n\n// decrypt decodes and decrypts a Base64-encoded AES-256-CBC ciphertext.\n// Layout after decryption + PKCS#7 unpad:\n//\n//\t[16 bytes random] [4 bytes msg_len (big-endian)] [msg_len bytes message] [corp_id]\nfunc (p *Platform) decrypt(cipherBase64 string) (string, error) {\n\tcipherData, err := base64.StdEncoding.DecodeString(cipherBase64)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"base64 decode: %w\", err)\n\t}\n\n\tblock, err := aes.NewCipher(p.aesKey)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"aes new cipher: %w\", err)\n\t}","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L722-L758","documentation":"Configuration guard in decodeAESKey, called from New: the WeCom EncodingAESKey from config.toml is not exactly 43 characters. WeCom issues these keys as 43-char Base64 (without padding) that decodes, with one appended '=', to the 32-byte AES key; any other length cannot be a valid key and startup is aborted.","triggerScenarios":"Thrown at platform/wecom/wecom.go:740 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Copy the EncodingAESKey exactly from the WeCom admin console — no trailing '=' or whitespace","Trim stray whitespace/newlines from the config value before validating","If the key was regenerated in the console, update config.toml with the new 43-char value","Fail fast at startup (as the code does) so misconfiguration is caught before serving"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}