25 lines
694 B
Go
25 lines
694 B
Go
package haiyuapi
|
||
|
||
import (
|
||
"encoding/json"
|
||
|
||
"tyapi-server/internal/shared/crypto"
|
||
)
|
||
|
||
// EncryptParams 将业务参数序列化为 JSON 后,使用 Access Key(16进制)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)
|
||
}
|