Documentation
¶
Overview ¶
Package cdn talks to the WeChat C2C CDN: encrypts files locally with AES-128-ECB, hands them to the upload endpoint, and inverts the flow on the download side. It exists as its own package so the listener layer doesn't have to carry the iLink-specific crypto helpers, and so tests can target the CDN protocol without spinning up the full long-poll listener.
Index ¶
- Variables
- func Decrypt(ciphertext, key []byte) ([]byte, error)
- func Download(ctx context.Context, encryptQueryParam, aesKeyBase64 string) ([]byte, error)
- func Encrypt(plaintext, key []byte) ([]byte, error)
- func HexDecodedAsBase64(hexKey string) string
- func HexStringAsBase64(hexKey string) string
- func PaddedSize(plaintextSize int) int
- func ParseAESKey(aesKeyBase64 string) ([]byte, error)
- type UploadedFile
Constants ¶
This section is empty.
Variables ¶
var BaseURL = "https://novac2c.cdn.weixin.qq.com/c2c"
BaseURL is declared as a var (not const) so tests can override it with an httptest.Server. In production it stays pinned to the live CDN.
Functions ¶
func Decrypt ¶
Decrypt decrypts AES-128-ECB data and strips PKCS7 padding.
SECURITY: ECB mode is insecure for general-purpose encryption because identical plaintext blocks produce identical ciphertext blocks. This helper exists only for WeChat iLink CDN protocol compatibility. Do not reuse it for local storage, tokens, secrets, or user data encryption.
func Encrypt ¶
Encrypt encrypts data using AES-128-ECB with PKCS7 padding.
SECURITY: ECB mode is insecure for general-purpose encryption because identical plaintext blocks produce identical ciphertext blocks. This helper exists only for WeChat iLink CDN protocol compatibility. Do not reuse it for local storage, tokens, secrets, or user data encryption.
func HexDecodedAsBase64 ¶
HexDecodedAsBase64 hex-decodes the key first, then base64-encodes the raw 16 bytes — i.e. hex → 16 bytes → base64. This is the encoding iLink uses for inbound image AES keys (per ParseAESKey's 16-byte branch).
Falls back to the HexStringAsBase64 encoding when the input isn't valid hex, matching upstream behaviour: some legacy payloads put the base64 form directly in the hex field.
func HexStringAsBase64 ¶
HexStringAsBase64 treats the hex key's ASCII characters as opaque bytes and base64-encodes them — i.e. base64("abcdef012345...") → "YWJjZGVmMDEyMzQ1..." so the receiver will base64-decode back to the hex string, then hex-decode to the 16-byte key. This is the encoding iLink expects for outbound file/voice/video AES keys (per ParseAESKey's 32-char-hex branch).
Pair with HexDecodedAsBase64 below; the names spell out the difference because the older `aesKeyToBase64` form hid the "treat-as-string" semantics.
func PaddedSize ¶
PaddedSize returns the size of the AES-128-ECB ciphertext for a plaintext of the supplied length, including the mandatory PKCS7 padding block.
func ParseAESKey ¶
ParseAESKey decodes a base64-encoded AES key. Two formats:
- base64(raw 16 bytes) → images (aes_key from media field)
- base64(32-char hex string) → file / voice / video