Files
tyapi-server/internal/infrastructure/external/haiyuapi/crypto.go

25 lines
694 B
Go
Raw Normal View History

2026-06-01 14:39:45 +08:00
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)
}