cdn

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESECBDecrypt

func AESECBDecrypt(ciphertext, key []byte) ([]byte, error)

AESECBDecrypt decrypts AES-128-ECB ciphertext and removes PKCS7 padding.

func AESECBEncrypt

func AESECBEncrypt(plaintext, key []byte) ([]byte, error)

AESECBEncrypt encrypts plaintext with AES-128-ECB and PKCS7 padding.

func AESECBPaddedSize

func AESECBPaddedSize(plaintextSize int) int

AESECBPaddedSize returns the ciphertext size after PKCS7 padding for AES-128-ECB.

func ParseAESKey

func ParseAESKey(b64Key string) ([]byte, error)

ParseAESKey decodes a base64-encoded AES key, handling two formats:

Format 1: base64(raw 16 bytes) — commonly used for images
Format 2: base64(hex string of 32 chars) — commonly used for files/voice/video

Types

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

Downloader downloads and decrypts files from the WeChat CDN.

func NewDownloader

func NewDownloader(doer client.HTTPDoer) *Downloader

NewDownloader creates a Downloader with the given HTTP doer.

func (*Downloader) Download

func (d *Downloader) Download(ctx context.Context, encryptQueryParam, aesKeyB64 string) ([]byte, error)

Download fetches an encrypted file from the CDN and decrypts it.

type Uploader

type Uploader struct {
	// contains filtered or unexported fields
}

Uploader uploads encrypted files to the WeChat CDN.

func NewUploader

func NewUploader(c *client.Client, opts ...UploaderOption) *Uploader

NewUploader creates an Uploader for the given client.

func (*Uploader) Upload

func (u *Uploader) Upload(ctx context.Context, data []byte, toUserID string, mediaType int) (*types.UploadedFileInfo, error)

Upload encrypts and uploads data to the CDN.

func (*Uploader) UploadFile

func (u *Uploader) UploadFile(ctx context.Context, filePath, toUserID string, mediaType int) (*types.UploadedFileInfo, error)

UploadFile reads a file from disk and uploads it to the CDN.

type UploaderOption

type UploaderOption func(*Uploader)

UploaderOption configures an Uploader.

func WithMaxRetries

func WithMaxRetries(n int) UploaderOption

WithMaxRetries sets the maximum number of retries for 5xx errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL