f
This commit is contained in:
21
internal/infrastructure/external/nuoer/crypto.go
vendored
21
internal/infrastructure/external/nuoer/crypto.go
vendored
@@ -36,3 +36,24 @@ func genMD5(s string) string {
|
||||
sum := md5.Sum([]byte(s))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
// MD5Encrypt 对业务入参做 MD5 加密(小写十六进制),用于 encryptionType=2。
|
||||
func MD5Encrypt(plaintext string) string {
|
||||
return genMD5(plaintext)
|
||||
}
|
||||
|
||||
// encryptBodyMD5 将 body 中各非空字段值转为 MD5 密文。
|
||||
func encryptBodyMD5(body map[string]string) map[string]string {
|
||||
if len(body) == 0 {
|
||||
return body
|
||||
}
|
||||
encrypted := make(map[string]string, len(body))
|
||||
for k, v := range body {
|
||||
if strings.TrimSpace(v) == "" {
|
||||
encrypted[k] = v
|
||||
continue
|
||||
}
|
||||
encrypted[k] = MD5Encrypt(v)
|
||||
}
|
||||
return encrypted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user