This commit is contained in:
Mrx
2026-06-01 14:39:45 +08:00
parent 928ff4d766
commit 8ab2a6d81d
14 changed files with 495 additions and 67 deletions

View File

@@ -0,0 +1,24 @@
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)
}