软加密

master
yiming 3 years ago
parent 7842d651f3
commit 3b887f8463

1
.gitignore vendored

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

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

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

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