[英]How to decrypt an encrypted column with the AES method?
所以,我有两个表,一个Patient
用ID表patient_id
和另一个表medical_file
与列patient
中, patien_id
与AES法(不是外键)加密。 我将Hibernate用于 ORM,在MedicalFile实体中,我使用 AES 加密在 setter 方法setPatient
加密patient
,并在 getter 方法getPatient
中解密以解密从数据库中获取的值。 编码 :
@Entity
@Table(name = "patient", schema = "public")
public class Patient extends BaseEntity{
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false, nullable = false)
private UUID id;
//....
}
@Entity
@Table(name = "medical_file", schema = "public")
public class MedicalFile extends BaseEntity {
@Column(name = "patient")
private String patient;
//...
public void setPatient(String patient) {
AES256TextEncryptor textEncryptor = new AES256TextEncryptor();
textEncryptor.setPassword("key");
this.patient = textEncryptor.encrypt(patient);
}
public String getPatient() {
AES256TextEncryptor textEncryptor = new AES256TextEncryptor();
textEncryptor.setPassword("key");
return textEncryptor.decrypt(patient);
}
}
所以当我想保存medical_file
表时,我必须加密patient
列,当我想获取病人的medical_file
时,我已经解密了'medical_file'表中的patient
列。
具有相同密钥的patient
的 AES 加密每次都不同的问题,因此当我有patient
patient_id
(与patient
medical_file
表中的patient
相同但未加密)并且我想加密以从medical_file
表中获取patient
,我得到了一个medical_file
表中不存在的不同值。
有什么建议可以解决这个问题吗?
如果我理解正确,那么您要做的是-
您将 AES 加密数据存储在表中,然后想再次根据加密数据检索它,但问题是每个 AES 加密都生成不同的值,您不可能在意 DB 中的匹配项。
我会建议它与其他AES加密数据一起放置更多的MD5 哈希列。 MD5 是不可逆的,但它每次都会为相同的输入生成相同的值(这主要用于存储密码)。 因此,下次当您要搜索时,您已经创建了输入的MD5 哈希,从数据库中找到它,然后使用AES 解密解密其余数据。
让我知道这是否有用。 忽略我答,如果我没有正确地得到您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.