forked from shuzheng/zheng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
330 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
master.jdbc.driver=com.mysql.jdbc.Driver | ||
master.jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/zheng?useUnicode\=true&characterEncoding\=utf-8&autoReconnect\=true | ||
master.jdbc.username=root | ||
master.jdbc.password=123456 | ||
master.jdbc.password=RwfC38sMIAc= | ||
|
||
slave.jdbc.driver=com.mysql.jdbc.Driver | ||
slave.jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/zheng?useUnicode\=true&characterEncoding\=utf-8&autoReconnect\=true | ||
slave.jdbc.username=root | ||
slave.jdbc.password=123456 | ||
slave.jdbc.password=RwfC38sMIAc= |
14 changes: 7 additions & 7 deletions
14
zheng-cms/zheng-cms-dao/src/main/resources/redis.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ip=127.0.0.1 | ||
port=6379 | ||
password= | ||
max_active=500 | ||
max_idle=5 | ||
max_wait=10000 | ||
timeout=10000 | ||
master.redis.ip=127.0.0.1 | ||
master.redis.port=6379 | ||
master.redis.password=z4SkijYyEBc= | ||
master.redis.max_active=500 | ||
master.redis.max_idle=5 | ||
master.redis.max_wait=10000 | ||
master.redis.timeout=10000 |
32 changes: 32 additions & 0 deletions
32
zheng-common/src/main/java/com/zheng/common/plugin/EncryptPropertyPlaceholderConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.zheng.common.plugin; | ||
|
||
import com.zheng.common.util.DESUtil; | ||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; | ||
|
||
/** | ||
* 支持加密配置文件插件 | ||
* Created by ZhangShuzheng on 2017/2/4. | ||
*/ | ||
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { | ||
|
||
private String[] propertyNames = { | ||
"master.jdbc.password", "slave.jdbc.password", "master.redis.password" | ||
}; | ||
|
||
/** | ||
* 解密指定propertyName的加密属性值 | ||
* @param propertyName | ||
* @param propertyValue | ||
* @return | ||
*/ | ||
@Override | ||
protected String convertProperty(String propertyName, String propertyValue) { | ||
for (String p : propertyNames) { | ||
if (p.equalsIgnoreCase(propertyName)) { | ||
return DESUtil.getDecryptString(propertyValue); | ||
} | ||
} | ||
return super.convertProperty(propertyName, propertyValue); | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
zheng-common/src/main/java/com/zheng/common/util/DESUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.zheng.common.util; | ||
|
||
import sun.misc.BASE64Decoder; | ||
import sun.misc.BASE64Encoder; | ||
|
||
import javax.crypto.Cipher; | ||
import javax.crypto.KeyGenerator; | ||
import java.security.Key; | ||
import java.security.SecureRandom; | ||
|
||
/** | ||
* DES加密算法工具类 | ||
* Created by ZhangShuzheng on 2017/2/4. | ||
*/ | ||
public class DESUtil { | ||
|
||
private static Key key; | ||
private static String KEY_STR = "zheng"; // 密钥 | ||
private static String CHARSETNAME = "UTF-8"; // 编码 | ||
private static String ALGORITHM = "DES"; // 加密类型 | ||
|
||
static { | ||
try { | ||
KeyGenerator generator = KeyGenerator.getInstance(ALGORITHM); | ||
generator.init(new SecureRandom(KEY_STR.getBytes())); | ||
key = generator.generateKey(); | ||
generator = null; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* 对str进行DES加密 | ||
* @param str | ||
* @return | ||
*/ | ||
public static String getEncryptString(String str) { | ||
BASE64Encoder base64encoder = new BASE64Encoder(); | ||
try { | ||
byte[] bytes = str.getBytes(CHARSETNAME); | ||
Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
cipher.init(Cipher.ENCRYPT_MODE, key); | ||
byte[] doFinal = cipher.doFinal(bytes); | ||
return base64encoder.encode(doFinal); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* 对str进行DES解密 | ||
* @param str | ||
* @return | ||
*/ | ||
public static String getDecryptString(String str) { | ||
BASE64Decoder base64decoder = new BASE64Decoder(); | ||
try { | ||
byte[] bytes = base64decoder.decodeBuffer(str); | ||
Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
cipher.init(Cipher.DECRYPT_MODE, key); | ||
byte[] doFinal = cipher.doFinal(bytes); | ||
return new String(doFinal, CHARSETNAME); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
String[] keys = { | ||
"", "123456" | ||
}; | ||
System.out.println("key | encryptString | decryptString"); | ||
for (String key : keys) { | ||
System.out.print(key + " | "); | ||
String encryptString = getEncryptString(key); | ||
System.out.print(encryptString + " | "); | ||
String decryptString = getDecryptString(encryptString); | ||
System.out.println(decryptString); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.