enkripsi database properties untuk spring

Bagaimana cara meng-enkripsi database.properties supaya password database ter-enkripsi ?

BISMILLAH

q> Pada applicationContext.xml bean untuk propertyConfigurer sebelum database.properties di-enkripsi

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/home/glassfish/ZKGLASS/database.properties" />
</bean>

q>File database.properties berada pada /home/glassfish/ZKGLASS/database.properties.

q> Ubah bean propertyConfigurer menjadi seperti ini :

<bean class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg>
<bean>
<property name="password" value="BLABLABLA"/>
</bean>
</constructor-arg>
<property name="locations">
<list>
<value>file:/home/glassfish/ZKGLASS/database.properties</value>
</list>
</property>
</bean>

bean di atas menggunakan library Jasypt. (jasypt-1.9.0.jar dan jasypt-spring3-1.9.0).

q> isi database properties setelah menggunakan bean jasypt :

jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.jdbcUrl=jdbc:oracle:thin:@192.168.56.2:1521:myoracle
jdbc.user=myuser
jdbc.password=ENC(So5FQj8CX+rj9+pM/qq5xlZeGv+AimoB)

q> Pada bean di atas pada property password = “BLABLABLA” merupakan password enkriptor

q> Bagaimana cara membuat password So5FQj8CX+rj9+pM/qq5xlZeGv+AimoB

q> Buat class di java

package com.ipi.util;

import org.jasypt.util.text.BasicTextEncryptor;

/**
* @author glassfish
*
* Oct 30, 2012
*/
public class JasyptMain {

public static void main(String[] args) {
String passwordEnkriptor = "BLABLABLA";
BasicTextEncryptor chiper = new BasicTextEncryptor();
chiper.setPassword(passwordEnkriptor);
String plainText = "passwordalay";
System.out.println("String "+plainText+" dienkripsi menjadi : "+chiper.encrypt(plainText));
}

}

q> Ataw klo mau bikin aplikasi GUI menggunakan java bisa dibuat seperti ini :

q> Untuk bean datasource

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}" />
<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
</bean>

End ::

ALHAMDULILLAH

Thank to Mas Endy Muhardin.

Sumber ::
http://software.endy.muhardin.com/java/enkripsi-jdbc-properties/

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s