{"record":{"id":"b7333cae90e793b2","repo":"chenhg5/cc-connect","slug":"s-encrypt-w","errorCode":null,"errorMessage":"%s: encrypt: %w","messagePattern":"(.+?): encrypt: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/weixin/cdn.go","lineNumber":180,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: decrypt: %w\", label, err)\n\t}\n\treturn plain, nil\n}\n\nfunc downloadPlainCDN(ctx context.Context, client *http.Client, cdnBase, encParam, label string) ([]byte, error) {\n\tu := buildCdnDownloadURL(encParam, cdnBase)\n\treturn fetchCdnBytes(ctx, client, u, label)\n}\n\nconst cdnUploadMaxRetries = 3\n\n// uploadBufferToCDN encrypts plaintext with AES-128-ECB and uploads to the given CDN URL.\n// Caller is responsible for building the full URL (via buildCdnUploadURL or from upload_full_url).\nfunc uploadBufferToCDN(ctx context.Context, client *http.Client, cdnURL string, plaintext, aesKey []byte, label string) (downloadParam string, err error) {\n\tciphertext, err := encryptAESECB(plaintext, aesKey)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: encrypt: %w\", label, err)\n\t}\n\tu := cdnURL\n\tvar lastErr error\n\tfor attempt := 1; attempt <= cdnUploadMaxRetries; attempt++ {\n\t\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, u, bytes.NewReader(ciphertext))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"%s: new request: %w\", label, err)\n\t\t}\n\t\treq.Header.Set(\"Content-Type\", \"application/octet-stream\")\n\t\tresp, err := client.Do(req)\n\t\tif err != nil {\n\t\t\tlastErr = err\n\t\t\tslog.Warn(\"weixin: CDN upload request failed\", \"label\", label, \"attempt\", attempt, \"error\", err)\n\t\t\tcontinue\n\t\t}\n\t\t_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 4096))\n\t\t_ = resp.Body.Close()\n\t\tif resp.StatusCode >= 400 && resp.StatusCode < 500 {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/cdn.go#L162-L198","documentation":"AES-128-ECB encryption of the outgoing media buffer failed in uploadBufferToCDN — crypto/aes rejected the key generated for the upload (e.g. wrong key length after key generation) or block encryption failed, so the media could not be prepared for Weixin CDN upload.","triggerScenarios":"Thrown at platform/weixin/cdn.go:180 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the generated upload key is exactly 16 bytes (AES-128) before encrypting","Log key length and plaintext size to pinpoint the crypto failure","Fail the specific send and report to the user; retry the whole upload with a fresh key"],"exampleFix":null,"handlingStrategy":"fallback","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"}