【发布时间】:2019-12-13 05:22:14
【问题描述】:
我正在尝试使用 mgo 和 Golang 加密 mongodb 中的某些字段。由于 mongodb 不支持字段级加密,所以我在考虑对数据进行加密和解密,同时对数据进行编组和解组。
例如,在下面的结构中我要加密 Name 和 Gender
如果我的结构是这样的
type User struct {
UserID string `json:"userID,omitempty" bson:"userID,omitempty"`
UserName string `json:"userName,omitempty" bson:"userName,omitempty"`
UserAge string `json:"userAge,omitempty" bson:"userAge,omitempty"`
UserGender string `json:"userGender,omitempty" bson:"userGender,omitempty"`
}
解决此问题的一种方法是在编组数据之后,在保存到数据库之前加密数据,以及将数据发送回 UI 的类似方法。在对数据进行编组和解组之前,是否有我可以收听的事件?或者有更好的方法吗?
【问题讨论】:
-
“事件”是对
GetBSON()和SetBSON()方法的实际调用。
标签: mongodb go encryption