1:添加数据库加密解密工具类
2:为clickhouse数据库添加账号密码
This commit is contained in:
47
src/main/java/com/nis/util/EncryptPassword.java
Normal file
47
src/main/java/com/nis/util/EncryptPassword.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.nis.util;
|
||||
|
||||
import com.google.api.client.util.Base64;
|
||||
import com.zdjizhi.crypt.AESUtil;
|
||||
/**
|
||||
* 加密解密工具类
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class EncryptPassword {
|
||||
public static void main(String[] args) {
|
||||
encryptPassword("k18");
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密密码
|
||||
*
|
||||
* @param key
|
||||
* @param encryptPassword
|
||||
*/
|
||||
private static void decipheringPassword(String key, String encryptPassword) {
|
||||
try {
|
||||
String realPwd = new String(AESUtil.decrypt(Base64.decodeBase64(encryptPassword), key));
|
||||
System.out.println("实际密码:" + realPwd);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密密码
|
||||
*
|
||||
* @param pwd
|
||||
*/
|
||||
private static void encryptPassword(String pwd) {
|
||||
try {
|
||||
String initKeyString = AESUtil.initKeyString();
|
||||
System.out.println("加密的key:" + initKeyString);
|
||||
String password = new String(Base64.encodeBase64(AESUtil.encrypt(pwd.getBytes(), initKeyString)));
|
||||
System.out.println("加密后密码: " + password);
|
||||
decipheringPassword(initKeyString, password);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user