Files
tyapi-server/internal/infrastructure/external/haiyuapi/crypto.go
2026-06-01 14:39:45 +08:00

25 lines
694 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package haiyuapi
import (
"encoding/json"
"tyapi-server/internal/shared/crypto"
)
// EncryptParams 将业务参数序列化为 JSON 后,使用 Access Key16进制AES-128-CBC 加密并 Base64 编码
func EncryptParams(params map[string]interface{}, accessKey string) (string, error) {
plainJSON, err := json.Marshal(params)
if err != nil {
return "", err
}
return crypto.AesEncrypt(plainJSON, accessKey)
}
// DecryptData 解密响应 data 字段IV+密文 Base64空字符串视为无数据返回 {}
func DecryptData(encrypted, accessKey string) ([]byte, error) {
if encrypted == "" {
return []byte("{}"), nil
}
return crypto.AesDecrypt(encrypted, accessKey)
}