Commit d8313c69 by hweeeeeei

优化AppSecret生成规则: 不使用key作为加密字符串,防止被破解

parent 4233f56a
...@@ -27,8 +27,8 @@ public class ImApplicationTest { ...@@ -27,8 +27,8 @@ public class ImApplicationTest {
private ImApplicationService imApplicationService; private ImApplicationService imApplicationService;
public static void main(String[] args) { public static void main(String[] args) {
String appKey = KeyGenerator.getAppKey(); //定义变量接收 String appKey = KeyGenerator.getRandomString(); //定义变量接收
String appSecret = KeyGenerator.getAppSecret(appKey); String appSecret = KeyGenerator.getAppSecret();
int i = 1; int i = 1;
} }
...@@ -42,10 +42,10 @@ public class ImApplicationTest { ...@@ -42,10 +42,10 @@ public class ImApplicationTest {
private void addDb( int i) { private void addDb( int i) {
// 生成AppKey // 生成AppKey
String appKey = KeyGenerator.getAppKey(); //定义变量接收 String appKey = KeyGenerator.getRandomString(); //定义变量接收
// 生成appSecret // 生成appSecret
String appSecret = KeyGenerator.getAppSecret(appKey); String appSecret = KeyGenerator.getAppSecret();
ImApplication imApplication = new ImApplication(); ImApplication imApplication = new ImApplication();
imApplication.setCreateTime(new Date()); imApplication.setCreateTime(new Date());
......
...@@ -12,8 +12,10 @@ public class KeyGenerator { ...@@ -12,8 +12,10 @@ public class KeyGenerator {
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z"}; "W", "X", "Y", "Z"};
//生成8位appKey /*
public static String getAppKey() { * 生成随机字符串
*/
public static String getRandomString() {
StringBuffer shortBuffer = new StringBuffer(); StringBuffer shortBuffer = new StringBuffer();
//获取用户id进行字符串截取 //获取用户id进行字符串截取
String uuid = UUID.randomUUID().toString().replace("-", ""); String uuid = UUID.randomUUID().toString().replace("-", "");
...@@ -25,15 +27,16 @@ public class KeyGenerator { ...@@ -25,15 +27,16 @@ public class KeyGenerator {
return shortBuffer.toString(); return shortBuffer.toString();
// return UUID.randomUUID().toString().replace("-", ""); // return UUID.randomUUID().toString().replace("-", "");
} }
//生成32位appSecret /*
public static String getAppSecret(String appId) { *生成32位appSecret
*/
public static String getAppSecret() {
String encryoAppSecret = ""; String encryoAppSecret = "";
try { try {
EncrypDES des1 = new EncrypDES();// 使用默认密钥 EncrypDES des1 = new EncrypDES();// 使用默认密钥
encryoAppSecret = des1.encrypt(appId); encryoAppSecret = des1.encrypt(KeyGenerator.getRandomString());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment