[Hibernate] DB 특정 값 암호화하여 사용하기~! (Jasypt)
Hibernate4를 기준으로 설명을 하겠습니다.
1. 라이브러리 추가
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-hibernate4</artifactId>
<version>1.9.1</version>
</dependency>
2. hibernate 설정
<bean id="strongEncryptor" class="org.jasypt.encryption.pbe.PooledPBEStringEncryptor">
<property name="algorithm">
<value>PBEWithMD5AndTripleDES</value>
</property>
<property name="password">
<value>jasypt</value>
</property>
<property name="poolSize">
<value>4</value>
</property>
</bean>
<bean id="hibernateStringEncryptor" class="org.jasypt.hibernate4.encryptor.HibernatePBEStringEncryptor">
<property name="registeredName">
<value>strongHibernateStringEncryptor</value>
</property>
<property name="encryptor">
<ref bean="strongEncryptor" />
</property>
</bean>
3. 사용하기 (2번에서 registerdName = strongHibernateStringEncryptor 이다.)
@TypeDef(
name="encryptedString",
typeClass=EncryptedStringType.class,
parameters= {
@Parameter(name="encryptorRegisteredName", value="strongHibernateStringEncryptor")
}
)
public class User {
@Column (name = "password", nullable= true)
@Type(type="encryptedString")
private String password;
}
4. 이제 그대로 사용만 하면~!된다.~!!!