软加密

master
yiming 3 years ago
parent 7842d651f3
commit 3b887f8463

1
.gitignore vendored

@ -33,3 +33,4 @@ target
/modules/filter/filter.iml /modules/filter/filter.iml
/modules/common/common.iml /modules/common/common.iml
lp.key lp.key
lp.lic

@ -2,12 +2,12 @@ package encryptor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public class Encryptor { public class Encryptor {
public native String encryptStr(String str); public native static String encryptStr(String str);
static static
{ {
try{ try{
String path = System.getProperty("user.dir")+"\\libs\\encrypt"; String path = System.getProperty("user.dir")+"\\libs\\encrypt";
System.out.println(path);
System.setProperty("java.library.path", path); System.setProperty("java.library.path", path);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true); fieldSysPath.setAccessible(true);
@ -21,9 +21,9 @@ public class Encryptor {
} }
public static void main(String[] args) public static void main(String[] args)
{ {
Encryptor encryptor = new Encryptor();
String noEncrypt = "12345"; String noEncrypt = "12345";
String encrypt = encryptor.encryptStr(noEncrypt); String encrypt = Encryptor.encryptStr(noEncrypt);
System.out.println(encrypt); System.out.println(encrypt);
} }
} }

@ -20,22 +20,32 @@ public class LPLicense {
private static String key_path = "./lp.key"; private static String key_path = "./lp.key";
private static String CPU_INFO = null;
/**
*
*/
public static void createLicKeyIfNotExist(){ public static void createLicKeyIfNotExist(){
File file = new File(key_path); File file = new File(key_path);
if(!file.exists()){ if(!file.exists()){
try { String cpu = getCpuInfo();
Process process = Runtime.getRuntime().exec( CPU_INFO = cpu;
new String[] { "wmic", "cpu", "get", "ProcessorId" }); FileUtil.save(cpu,key_path);
process.getOutputStream().close(); }
Scanner sc = new Scanner(process.getInputStream()); }
String property = sc.next();
String cpu = sc.next(); private static String getCpuInfo(){
FileUtil.save(cpu,key_path); try {
} catch (IOException e) { Process process = Runtime.getRuntime().exec(
e.printStackTrace(); new String[] { "wmic", "cpu", "get", "ProcessorId" });
log.error("createLicKeyIfNotExist error:{}",e); process.getOutputStream().close();
} Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String cpu = sc.next();
return cpu;
} catch (IOException e) {
log.error("createLicKeyIfNotExist error:{}",e);
return null;
} }
} }
@ -44,13 +54,13 @@ public class LPLicense {
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){ if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
lastUpdate = LocalDateTime.now(); lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path); lic_str = FileUtil.getText(lic_path);
CPU_INFO = getCpuInfo();
} }
return lic_str; return lic_str;
} }
public static boolean checkLic(String pathStr){ public static boolean checkLic(String licStr){
//todo 检测 return CPU_INFO != null && licStr.equals(encryptor.Encryptor.encryptStr(CPU_INFO));
return true;
} }
public static boolean checkLic(){ public static boolean checkLic(){

@ -1,5 +1,6 @@
package com.leaper.web.service; package com.leaper.web.service;
import com.leaper.filter.aspect.LPLicense;
import com.leaper.web.lib.CameraControlLoginModule; import com.leaper.web.lib.CameraControlLoginModule;
import com.leaper.web.lib.CameraControlModule; import com.leaper.web.lib.CameraControlModule;
import com.leaper.web.lib.TaskDelayExecutor; import com.leaper.web.lib.TaskDelayExecutor;
@ -84,6 +85,7 @@ public class InitService implements ApplicationRunner {
LoginThread loginThread = new LoginThread(camera); LoginThread loginThread = new LoginThread(camera);
loginThread.start(); loginThread.start();
}); });
LPLicense.createLicKeyIfNotExist();
//plc连接 //plc连接
if(configProperties.getServerMode() == 0){ if(configProperties.getServerMode() == 0){
log.info("PLC TCP MODE"); log.info("PLC TCP MODE");

@ -1,69 +0,0 @@
package com.leaper.web.service;
import com.leaper.common.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Scanner;
@Slf4j
public class LPLicense {
private static LocalDateTime lastUpdate = null;
private static String lic_str = null;
private static String lic_path = "./lp.lic";
private static String key_path = "./lp.key";
public static void createLicKeyIfNotExist(){
File file = new File(key_path);
if(!file.exists()){
try {
Process process = Runtime.getRuntime().exec(
new String[] { "wmic", "cpu", "get", "ProcessorId" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String cpu = sc.next();
FileUtil.save(cpu,key_path);
} catch (IOException e) {
e.printStackTrace();
log.error("createLicKeyIfNotExist error:{}",e);
}
}
}
public static String getLic(){
//每小时读取一次lic文件
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path);
}
return lic_str;
}
public static boolean checkLic(String pathStr){
//todo 检测
return true;
}
public static boolean checkLic(){
String licStr = getLic();
if(StringUtils.isEmpty(licStr)){
return false;
}
return checkLic(licStr);
}
public static void main(String[] args) {
createLicKeyIfNotExist();
}
}
Loading…
Cancel
Save