sipeed/picoclaw · error

ciphertext is empty

Error message

ciphertext is empty

What it means

Guard in decryptAESCBC: the media ciphertext handed in for decryption is zero-length, so AES-CBC decryption cannot proceed. This indicates upstream extraction of the encrypted payload from the WeCom media response produced nothing.

Solutions

  1. Check how the ciphertext was extracted from the downloaded media response (body slicing may have consumed it)
  2. Re-download the media and verify the response actually contains an encrypted payload
  3. Check content-length and that the download wasn't an error body
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/channels/wecom/media.go:106 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/840ca2b31abfb650. Report an issue: GitHub.

Appendix: source

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

		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)
	return pkcs7Unpad(plaintext)
}

func pkcs7Unpad(data []byte) ([]byte, error) {
	if len(data) == 0 {
		return nil, fmt.Errorf("empty plaintext")
	}

View on GitHub (pinned to 49183d7e8d)