下記手順通り。
1> maven dependencyの追加
<!– https://mvnrepository.com/artifact/org.jasypt/jasypt-spring3 –>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring3</artifactId>
<version>1.9.2</version>
</dependency>
2>set environment in eclipse : CAS_PBE_PASSWORD=master password
ここを参考し、変数を設定します。
https://stackoverflow.com/questions/7048216/environment-variables-in-eclipse
3> Encrypt your credentials
Jasypt provides a command line utility that can be used to encrypt the values of your properties. Download the Jasypt distribution and unpack it. The utilities reside in the bin directory.
encrypt input=”pa55word” password=”master password” algorithm=”PBEWITHMD5ANDDES”
Windowsでの実行方法:
cmdでコマンドラインを起動します。encrypt.batのあるフォルダは以下へ移動します。
下記コマンドを実行します。
encrypt.bat input="pa55word" password="master password" algorithm="PBEWITHMD5ANDDES"
こんな感じで暗号化したパスワードが表示されます。
4>Read credentials in a properties file i.e. database.properties
dataSource.password=ENC(4nZEPG531tZ4CmBjnni8oDicrXxyza9j)
dataSource.username=root
5>you can have it old way in a xml.
<bean id="propertyPlaceholderConfigurer"
class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="location" value="classpath:jdbc.properties" />
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration" />
</bean>
<bean id="environmentVariablesConfiguration"
class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWITHMD5ANDDES" />
<property name="passwordEnvName" value="CAS_PBE_PASSWORD" />