sipeed/picoclaw · error

invalid AES key length

Error message

invalid AES key length %d

What it means

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.

Solutions

  1. Regenerate the EncodingAESKey in the WeCom admin console so it decodes to exactly 32 bytes (standard 43-character key)
  2. Check for accidental extra or missing characters that shift the decoded length
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/channels/wecom/media.go:99 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/8301d76df28e8909. Report an issue: GitHub.

Appendix: source

Thrown at pkg/channels/wecom/media.go:99

		}
	}
	return body
}

func decodeMediaAESKey(value string) ([]byte, error) {
	if value == "" {
		return nil, nil
	}
	key, err := base64.StdEncoding.DecodeString(value)
	if err == nil && len(key) == 32 {
		return key, nil
	}
	key, err = base64.StdEncoding.DecodeString(value + "=")
	if err != nil {
		return nil, fmt.Errorf("decode AES key: %w", err)
	}
	if len(key) != 32 {
		return nil, fmt.Errorf("invalid AES key length %d", len(key))
	}
	return key, nil
}

func decryptAESCBC(key, ciphertext []byte) ([]byte, error) {
	if len(ciphertext) == 0 {
		return nil, fmt.Errorf("ciphertext is empty")
	}
	if len(ciphertext)%aes.BlockSize != 0 {
		return nil, fmt.Errorf("ciphertext length %d is not a multiple of block size", len(ciphertext))
	}
	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, fmt.Errorf("create cipher: %w", err)
	}
	plaintext := make([]byte, len(ciphertext))
	iv := key[:aes.BlockSize]
	cipher.NewCBCDecrypter(block, iv).CryptBlocks(plaintext, ciphertext)

View on GitHub (pinned to 49183d7e8d)