|
@ -20,14 +20,14 @@ public class ModuleAuthenUtils { |
|
|
public static String secretKey; |
|
|
public static String secretKey; |
|
|
public static Map<String,String> module = new HashMap<>(); |
|
|
public static Map<String,String> module = new HashMap<>(); |
|
|
@Resource RedisTemplate redisTemplate; |
|
|
@Resource RedisTemplate redisTemplate; |
|
|
public String decrypt(String encryptedData,String secretKey) throws Exception { |
|
|
public static String decrypt(String encryptedData,String secretKey) throws Exception { |
|
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); |
|
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); |
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); |
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); |
|
|
byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData)); |
|
|
byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData)); |
|
|
return new String(decryptedBytes, StandardCharsets.UTF_8); |
|
|
return new String(decryptedBytes, StandardCharsets.UTF_8); |
|
|
} |
|
|
} |
|
|
public String encrypt(String data,String secretKey) throws Exception { |
|
|
public static String encrypt(String data,String secretKey) throws Exception { |
|
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); |
|
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); |
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); |
|
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); |
|
@ -36,15 +36,15 @@ public class ModuleAuthenUtils { |
|
|
} |
|
|
} |
|
|
public void updateLicences(LicencesMessage ...message){ |
|
|
public void updateLicences(LicencesMessage ...message){ |
|
|
if(message != null && message.length>0){ |
|
|
if(message != null && message.length>0){ |
|
|
ModuleAuthenUtils.secretKey = message[0].getSecretKey(); |
|
|
secretKey = message[0].getSecretKey(); |
|
|
ModuleAuthenUtils.module = message[0].getData(); |
|
|
module = message[0].getData(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
JSONObject json = new JSONObject(redisTemplate.opsForValue().get(ModuleAuthenUtils.LICENCES_REDIS_KEY)); |
|
|
JSONObject json = new JSONObject(redisTemplate.opsForValue().get(LICENCES_REDIS_KEY)); |
|
|
if(json.isEmpty()){ |
|
|
if(json.isEmpty()){ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
ModuleAuthenUtils.secretKey = json.getStr("secretKey"); |
|
|
secretKey = json.getStr("secretKey"); |
|
|
ModuleAuthenUtils.module = json.getJSONObject("data").toBean(Map.class); |
|
|
module = json.getJSONObject("data").toBean(Map.class); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|