软加密

chongqing-yashichuangneng
LAPTOP-S9HJSOEB\昊天 3 years ago
parent 4f1616d405
commit 5fb1b59bed

Binary file not shown.

@ -0,0 +1,29 @@
package encryptor;
import java.lang.reflect.Field;
public class Encryptor {
public native static String encryptStr(String str);
static
{
try{
String path = System.getProperty("user.dir")+"\\libs\\encrypt";
System.setProperty("java.library.path", path);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
System.loadLibrary("Encryptor");
}catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String[] args)
{
String noEncrypt = "12345";
String encrypt = Encryptor.encryptStr(noEncrypt);
System.out.println(encrypt);
}
}

@ -0,0 +1,99 @@
package com.zhehekeji.filter.aspect;
import com.zhehekeji.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";
private static String CPU_INFO = null;
private static String DISK_INFO = null;
/**
*
*/
public static void createLicKeyIfNotExist(){
File file = new File(key_path);
if(!file.exists()){
String cpu = getCpuInfo();
CPU_INFO = cpu;
String disk = getDiskInfo();
DISK_INFO = disk;
FileUtil.save(cpu+disk,key_path);
}
}
private static String getCpuInfo(){
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();
return cpu;
} catch (IOException e) {
log.error("GET CPU error:{}",e);
return null;
}
}
private static String getDiskInfo(){
try {
Process process = Runtime.getRuntime().exec(
new String[] { "wmic","diskdrive","where","index=0", "get", "serialnumber"});
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String disk = sc.next();
return disk;
} catch (IOException e) {
log.error("Get DISK error:{}",e);
return null;
}
}
public static String getLic(){
//每小时读取一次lic文件
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path);
CPU_INFO = getCpuInfo();
DISK_INFO = getDiskInfo();
}
return lic_str;
}
public static boolean checkLic(String licStr){
return CPU_INFO != null && DISK_INFO != null && licStr.equals(encryptor.Encryptor.encryptStr(CPU_INFO+DISK_INFO));
}
public static boolean checkLic(){
String licStr = getLic();
if(StringUtils.isEmpty(licStr)){
return false;
}
return checkLic(licStr);
}
public static void main(String[] args) {
createLicKeyIfNotExist();
}
}

@ -0,0 +1,24 @@
package com.zhehekeji.filter.aspect;
import com.zhehekeji.core.util.Assert;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class LicenseAspect {
/**
* leaper..*.controller
* leaper controller
*
* @param
*/
@Before("execution(public * com.zhehekeji..*.controller.*.*(..))")
public void handler(){
Assert.isTrue(LPLicense.checkLic(),"未获取授权请将C:\\hzleaper_auto_install\\logistics_package\\lp.key发送给授权人员");
}
}

@ -1,5 +1,6 @@
package com.zhehekeji.web.service;
import com.zhehekeji.filter.aspect.LPLicense;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.Camera;
import com.zhehekeji.web.entity.Street;
@ -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");

Loading…
Cancel
Save