问题
I was wondering if my idea is possible with hibernate.
What I want is that there is one table with usernames and every table wich has a reference to this table has the username encrypted in a column. So the username doesn't stand in normal text but encrypted in every table which have a reference to the user table.
So I need something like:
@ManyToOne
@JoinColumn(name = "userName", insertable=false, updatable=false, encrypted="md5")
public User getUser(){
return this.user;
}
public void setUser(User user ){
this.user = user;
}
I hope that I make myself clear.
回答1:
You should implement this using a custom UserType
and Jasypt (Java Simplified Encryption) actually provides a basic set of Hibernate UserType
that may suit your needs.
See also
- Security: Transparent encryption of persisted data (with Jasypt UserTypes)
来源:https://stackoverflow.com/questions/3282245/hibernate-encrypted-reference-by-relations-on-usernames