Encryption Spring MVC:使用用户密码进行加密/解密
我正在开发一个SpringMVC应用程序,它使用Hibernate作为 ORM和PostgreSQL作为数据库,我正在寻找 即时加密解密解决方案,但仅适用于中的2列 数据库,其余的都可以保持非加密状态。我有一个人 实体,它有一个密码,我正在用 BCrypt并将其保存在数据库中。我知道一旦密码被BCrypt加密,我就无法解密。我计划暂时放置一个中间页面,在那里我将再次请求密码,并将其保存为某种格式,以便用于即时加密解密Encryption Spring MVC:使用用户密码进行加密/解密,encryption,authentication,database,bcrypt,Encryption,Authentication,Database,Bcrypt,我正在开发一个SpringMVC应用程序,它使用Hibernate作为 ORM和PostgreSQL作为数据库,我正在寻找 即时加密解密解决方案,但仅适用于中的2列 数据库,其余的都可以保持非加密状态。我有一个人 实体,它有一个密码,我正在用 BCrypt并将其保存在数据库中。我知道一旦密码被BCrypt加密,我就无法解密。我计划暂时放置一个中间页面,在那里我将再次请求密码,并将其保存为某种格式,以便用于即时加密解密 如果可能的话,我想用这个密码来加密/解密 一旦用户登录并对这两个列执行操作,
- 如果可能的话,我想用这个密码来加密/解密 一旦用户登录并对这两个列执行操作,这两个列就会出现 列
- 由于我也在使用Spring安全性,因此我正在注入编码器bean Spring Security可以登录用户。下面是我如何拯救世界的 密码和我的安全应用程序上下文。因为我才刚刚开始 有了这个问题,没有那么多进展可以粘贴到这里:
@Entity
@Table(name="person")
public class Person implements UserDetails{
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "person_seq_gen")
@SequenceGenerator(name = "person_seq_gen",sequenceName = "person_seq")
private int id;
@Valid
@Email
@Pattern(regexp = emailRegexp)
@Column(name = "username")
private String username;
@Valid
@NotEmpty(message = "Password may not be empty")
@Column(name = "password")
private String password;
// getters and setters ommitted }
PersonServiceImpl:
@Override
@Transactional
public boolean addPerson(Person p) {
Person existingUser = personDAO.findPersonByUsername(p.getUsername());
if(existingUser == null) {
this.personDAO.addPerson(p);
p.setAccountstatus(false);
p.setOnetimeemail(false);
p.setUsername(p.getUsername().toLowerCase());
// as you can see I am encrypting the password and saving in DB, I don't know how to access the plain password at this point to use in some algorithm for on-the-fly encryption/decryption
p.setPassword(BCrypt.hashpw(p.getPassword(), BCrypt.gensalt(11)));
p.setUsername(p.getUsername().toLowerCase());
this.personDAO.addPerson(p);
sendAccountActivationEmail(p.getUsername(), p.getFirstName());
return true;
} else {
return false;
}
}
Security-application-context.xml
<beans:bean id="encoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
<beans:constructor-arg name="strength" value="11" />
</beans:bean>
<beans:bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="LoginServiceImpl"/>
<beans:property name="passwordEncoder" ref="encoder"/>
</beans:bean>
任何指点,帮助都很好。如果有任何不清楚的地方,请告诉我。非常感谢