[英]Spring Boot: Perform encryption/decryption using Annotation: MongoDB
I have a requirement where I have to encrypt a field before saving in the database and decrypt it while retrieving it.我有一个要求,我必须在保存到数据库之前加密一个字段并在检索它时解密它。 The fields that should be encrypted should be custom annotated.应加密的字段应进行自定义注释。
I am using spring-boot with MongoDB for this.我为此使用 spring-boot 和 MongoDB。
Example:例子:
Class Person {
Long ID;
String userName;
String password;
@EncryptThisField
String firstName;
@EncryptThisField
String lastName;
... SETTER and GETTERS
}
Based on annotation my setter should set encrypted value(and save to database) and getter should return decrypted value(and retrieve from database).根据注释,我的 setter 应该设置加密值(并保存到数据库),getter 应该返回解密值(并从数据库中检索)。
Any pointers or suggestions?任何指示或建议?
you should create two functional-interface.您应该创建两个功能接口。 One to encrypt and other decrypt.一个加密,另一个解密。 use the annotation on the setter and getter methods instead of on the field.在 setter 和 getter 方法上使用注释,而不是在字段上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.