LoginSignup
1
1

More than 3 years have passed since last update.

Jasyptを利用したproperty fileの暗号化練習

Last updated at Posted at 2019-05-31

下記手順通り。

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"
こんな感じで暗号化したパスワードが表示されます。
image.png

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.

properties
<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" />

参考リンク

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1