-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.go
More file actions
23 lines (21 loc) · 780 Bytes
/
decrypt.go
File metadata and controls
23 lines (21 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package gorm_masking
import (
"github.com/labstack/gommon/log"
"gorm.io/gorm"
"reflect"
)
func decrypt(src, refValue reflect.Value, filedName string, db *gorm.DB) {
dbField := db.Statement.Schema.LookUpField(filedName)
if desensitizationType, ok := dbField.Tag.Lookup(MaskingTag); ok {
dType := MaskingType(desensitizationType)
dFunc := typeOptions[dType]
encryptColumn, _ := dbField.Tag.Lookup(MaskingEncryptColumnTag)
encryptField := db.Statement.Schema.LookUpField(encryptColumn).StructField.Name
encryptValue := src.FieldByName(encryptField).String()
if len(encryptValue) > 0 {
actualValue := dFunc.UnMasking(encryptValue, dbField, db)
log.Infof("encryptValue:%s,actualValue:%s", encryptValue, actualValue)
refValue.SetString(actualValue)
}
}
}