98 lines
3.5 KiB
Plaintext
98 lines
3.5 KiB
Plaintext
## 📋 数据库密码加密操作步骤
|
||
|
||
### 步骤1:编译项目
|
||
```bash
|
||
cd "e:\GTSOFT\111---项目文档---111\岱岳\批量\MpsSimulationBatch"
|
||
mvn clean compile -Dfile.encoding=UTF-8
|
||
```
|
||
|
||
### 步骤2:生成加密密钥文件
|
||
```bash
|
||
java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil genkey
|
||
```
|
||
此命令会在 `conf/.key` 文件中生成加密密钥。
|
||
|
||
### 步骤3:加密MySQL密码
|
||
```bash
|
||
java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil encrypt "c12321456"
|
||
```
|
||
记录输出的加密结果,格式类似:`ENC(xxxxxxxxxxxxxxx)`
|
||
|
||
### 步骤4:加密达梦数据库密码
|
||
```bash
|
||
java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil encrypt "SYSDBA"
|
||
```
|
||
同样记录输出的加密结果。
|
||
|
||
### 步骤5:修改配置文件
|
||
打开 `conf/application.properties` 文件,将明文密码替换为加密后的密码:
|
||
|
||
**修改前:**
|
||
```properties
|
||
db.mysql.password=c12321456
|
||
db.dm.password=SYSDBA
|
||
```
|
||
|
||
**修改后:**
|
||
```properties
|
||
db.mysql.password=ENC(步骤3的加密结果)
|
||
db.dm.password=ENC(步骤4的加密结果)
|
||
```
|
||
|
||
### 步骤6:设置文件权限(推荐)
|
||
```bash
|
||
# 设置配置文件只有所有者可读写
|
||
chmod 600 conf/application.properties
|
||
chmod 600 conf/.key
|
||
```
|
||
|
||
### 步骤7:测试验证
|
||
运行程序验证加密配置是否正常工作:
|
||
```bash
|
||
java -Dfile.encoding=UTF-8 -classpath "target\classes;C:\Users\CYQ\.m2\repository\com\mysql\mysql-connector-j\8.0.33\mysql-connector-j-8.0.33.jar;C:\Users\CYQ\.m2\repository\com\google\protobuf\protobuf-java\3.21.9\protobuf-java-3.21.9.jar;C:\Users\CYQ\.m2\repository\com\dameng\DmJdbcDriver18\8.1.3.140\DmJdbcDriver18-8.1.3.140.jar;C:\Users\CYQ\.m2\repository\org\slf4j\slf4j-api\2.0.7\slf4j-api-2.0.7.jar;C:\Users\CYQ\.m2\repository\ch\qos\logback\logback-classic\1.4.11\logback-classic-1.4.11.jar;C:\Users\CYQ\.m2\repository\ch\qos\logback\logback-core\1.4.11\logback-core-1.4.11.jar" com.gtsoft.mps.batch.MpsSimulationBatchMain -rerun 20250901
|
||
```
|
||
|
||
## 🔍 验证密码加密功能
|
||
如果需要验证加密是否正确,可以解密测试:
|
||
```bash
|
||
java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil decrypt "加密后的密文(不含ENC())"
|
||
```
|
||
|
||
## ⚠️ 重要注意事项
|
||
|
||
1. **密钥文件安全**:
|
||
- `conf/.key` 文件包含加密密钥,必须妥善保管
|
||
- 建议设置文件权限为 600(仅所有者可读写)
|
||
- 不要将密钥文件提交到版本控制系统
|
||
|
||
2. **配置格式**:
|
||
- 加密后的密码必须用 `ENC()` 包围
|
||
- 例如:`db.mysql.password=ENC(aBcDeFg123456789)`
|
||
|
||
3. **备份原配置**:
|
||
- 建议先备份原始的 [application.properties] 文件
|
||
- 以防加密过程中出现问题
|
||
|
||
4. **部署环境**:
|
||
- 生产环境部署时,确保 `conf/.key` 文件一起部署
|
||
- 确保运行用户对密钥文件有读取权限
|
||
|
||
## 🚀 自动化脚本(可选)
|
||
您也可以创建一个脚本来自动化这个过程:
|
||
|
||
**encrypt-passwords.bat**
|
||
```batch
|
||
@echo off
|
||
echo 正在编译项目...
|
||
mvn clean compile -Dfile.encoding=UTF-8 -q
|
||
|
||
echo 正在生成密钥文件...
|
||
java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil genkey
|
||
|
||
echo 请手动运行以下命令加密密码:
|
||
echo java -Dfile.encoding=UTF-8 -cp target/classes com.gtsoft.mps.batch.util.ConfigEncryptUtil encrypt "your-password"
|
||
|
||
pause
|
||
```
|
||
|
||
这样就完成了数据库密码的加密配置!程序会自动识别 `ENC()` 格式的密码并进行解密使用。 |