简体   繁体   English

Spring 引导:使用注释执行加密/解密:MongoDB

[英]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.

相关问题 使用 Spring 的密码加密/解密 - Password Encryption / Decryption using Spring 使用 Spring 启动的简单密码加密 - Simple Password Encryption using Spring Boot 什么是用于执行Azure Blob加密/解密的默认加密策略 - What is default encryption policy that is used to perform encryption/decryption of Azure blobs Spring 开机。 使用@ConfigurationProperties 注解的好处 - Spring boot. The profit of using @ConfigurationProperties annotation 在春季启动中使用@autowire注释会引发'BeanCreationException' - Using @autowire annotation in spring boot is throwing 'BeanCreationException' 在 RabbitMQ Listener 中使用 Spring Boot @MockBean 注解 - Using Spring Boot @MockBean annotation in RabbitMQ Listener 如何使用 secp256r1 Elliptical Curve 密钥对在 java 中执行加密和解密? - How to perform encryption and decryption in java using secp256r1 Elliptical Curve key pair? MongoDB 使用 spring-boot 注释创建复合索引文本和 NumberLong - MongoDB create compund index text and NumberLong with spring-boot annotation Spring Boot MongoDB 带版本注解的字段不自增 - Spring Boot MongoDB the field with version annotation does not increment 使用 JAVA 进行 RSA 加密/解密 - RSA Encryption/Decryption using JAVA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM