parent
c7f04cd807
commit
a45c911e95
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 = "BFEBFBFF000A06530026_B768_466D_0235.";
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue