获取硬件信息

For those who would like to see ready-to-use solution, I’m including links to the three classes I wrote to get machine SN on Windows, Linux and Mac OS:

oshi项目

Java License保护 - 图1

Supported platforms

Windows • Linux • macOS • Unix (AIX, FreeBSD, OpenBSD, Solaris)

参考项目:cryptolens-java

https://github.com/Cryptolens/cryptolens-java

特点

  • 使用oshi项目获取硬件信息
  • 支持多种语言
  • API设计友好
  • 商业

Java License保护 - 图2

There are two pre-compiled jar files: cryptolens.jar and cryptolens-android.jar. If your application is cross platform or if you would like to have as few dependencies as possible (e.g., without slf4j), we recommend to use cryptolens-android.jar instead.

License校验示例

  1. import io.cryptolens.methods.*;
  2. import io.cryptolens.models.*;
  3. public class Main {
  4. public static void main(String[] args) {
  5. String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
  6. String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
  7. LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()));
  8. if (license == null || !Helpers.IsOnRightMachine(license)) {
  9. System.out.println("The license does not work.");
  10. } else {
  11. System.out.println("The license is valid!");
  12. System.out.println("It will expire: " + license.Expires);
  13. }
  14. }
  15. }

获取硬件信息:

https://github.com/Cryptolens/cryptolens-java/blob/7548a9c76692aecaea87c36deca1d747f49874ef/src/main/java/io/cryptolens/methods/Helpers.java#L421

  1. private static String getRawDeviceID()
  2. {
  3. //thanks to https://stackoverflow.com/a/37705082. may require root.
  4. SystemInfo systemInfo = new SystemInfo();
  5. OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
  6. HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware();
  7. CentralProcessor centralProcessor = hardwareAbstractionLayer.getProcessor();
  8. ComputerSystem computerSystem = hardwareAbstractionLayer.getComputerSystem();
  9. String vendor = operatingSystem.getManufacturer();
  10. String processorSerialNumber = computerSystem.getSerialNumber();
  11. String processorIdentifier = centralProcessor.getProcessorIdentifier().getIdentifier();
  12. int processors = centralProcessor.getLogicalProcessorCount();
  13. return vendor +
  14. processorSerialNumber +
  15. processorIdentifier +
  16. processors;
  17. }