dawdler-encrypt-generator
Module Introduction
A key generation tool used to generate the keys used for encryption in properties files and the unified configuration center.
1. Usage
1.1 Installation
Install via mvn
mvn install
1.2 Generating the Key File and Setting the Environment Variable
After installation, you can run dawdler-encrypt-generator from the command line to generate the key and encrypted content.
java -jar dawdler-encrypt-generator-0.1.7-jdk25-RELEASES.jar
After running, the key used for encryption is generated and stored in the dawdler.password file.
The reminder is as follows:
generated file:[/home/srchen/github/dawdler-series/dawdler/dawdler-encrypt-generator/target/dawdler.password]
please set DAWDLER_ENCRYPT_FILE=/home/srchen/github/dawdler-series/dawdler/dawdler-encrypt-generator/target/dawdler.password to environment!
Setting the environment variable in Linux
export DAWDLER_ENCRYPT_FILE=/home/srchen/github/dawdler-series/dawdler/dawdler-encrypt-generator/target/dawdler.password
Or add it to .bashrc
export DAWDLER_ENCRYPT_FILE=/home/srchen/github/dawdler-series/dawdler/dawdler-encrypt-generator/target/dawdler.password
It is recommended to change the location of the dawdler.password file.
For example:
mv /home/srchen/github/dawdler-series/dawdler/dawdler-encrypt-generator/target/dawdler.password /home/srchen/dawdler-server/dawdler.password
Then the environment variable is set to /home/srchen/dawdler-server/dawdler.password.
1.3 Encrypting Content
After the environment variable has been set, encrypt the content.
java -jar dawdler-encrypt-generator-0.1.7-jdk25-RELEASES.jar 123456
#123456 is the original password
Console output
123456 -> [%2FkVZfdVQAuyD%2FXUNqzSQGw%3D%3D]
The encrypted password is between [].
1.4 Using the Encrypted Password in a properties Configuration File
To use encrypted content in properties, mark it with ENC(encrypted content).
addr=localhost
port=6379
auth=ENC(%2FkVZfdVQAuyD%2FXUNqzSQGw%3D%3D)
pool.maxTotal=20 #Maximum number of connections
pool.minIdle=2 #Minimum number of idle connections
pool.maxIdle=8 #Maximum number of idle connections
pool.maxWaitMillis=10000 #Maximum waiting duration (in milliseconds)
pool.testOnBorrow=false #Whether to validate the connection when borrowing it; default is false
pool.testOnCreate=false #Whether to validate the connection when creating it; default is false
pool.testOnReturn=false #Whether to validate the connection when returning it; default is false
timeout=10000
Currently supported modules are rabbitmq, redis, elasticSearch, and all custom properties applications that are read via club.dawdler.util.PropertiesUtil.
1.5 Using the Encrypted Password in the Configuration Center
type: com.zaxxer.hikari.HikariDataSource
jdbcUrl: jdbc:mysql://localhost:3306/mydb?characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: ENC(hTGici8M3cMAvJ6wrEXnwQ%3D%3D)
maximumPoolSize: 20
minimumIdle: 0