|
|
@ -20,14 +20,14 @@ public class ModuleAuthenUtils { |
|
|
|
public static String secretKey; |
|
|
|
public static Map<String,String> module = new HashMap<>(); |
|
|
|
@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); |
|
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); |
|
|
|
byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData)); |
|
|
|
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); |
|
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); |
|
|
@ -36,15 +36,15 @@ public class ModuleAuthenUtils { |
|
|
|
} |
|
|
|
public void updateLicences(LicencesMessage ...message){ |
|
|
|
if(message != null && message.length>0){ |
|
|
|
ModuleAuthenUtils.secretKey = message[0].getSecretKey(); |
|
|
|
ModuleAuthenUtils.module = message[0].getData(); |
|
|
|
secretKey = message[0].getSecretKey(); |
|
|
|
module = message[0].getData(); |
|
|
|
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()){ |
|
|
|
return; |
|
|
|
} |
|
|
|
ModuleAuthenUtils.secretKey = json.getStr("secretKey"); |
|
|
|
ModuleAuthenUtils.module = json.getJSONObject("data").toBean(Map.class); |
|
|
|
secretKey = json.getStr("secretKey"); |
|
|
|
module = json.getJSONObject("data").toBean(Map.class); |
|
|
|
} |
|
|
|
} |
|
|
|