LicenseManager.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import java.nio.charset.StandardCharsets;
  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. public class LicenseManager {
  5. private static final String SECRET_KEY = "YourSecretKey"; // 시크릿 키
  6. public static String generateLicenseKey(String computerName) {
  7. try {
  8. MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
  9. byte[] inputBytes = (computerName + SECRET_KEY).getBytes(StandardCharsets.UTF_8);
  10. byte[] hashBytes = sha1.digest(inputBytes);
  11. StringBuilder hexString = new StringBuilder();
  12. for (byte hashByte : hashBytes) {
  13. String hex = Integer.toHexString(0xff & hashByte);
  14. if (hex.length() == 1) {
  15. hexString.append('0');
  16. }
  17. hexString.append(hex);
  18. }
  19. return hexString.toString();
  20. } catch (NoSuchAlgorithmException e) {
  21. e.printStackTrace();
  22. return null;
  23. }
  24. }
  25. public static boolean validateLicenseKey(String computerName, String licenseKey) {
  26. return licenseKey.equals(generateLicenseKey(computerName));
  27. }
  28. public static void main(String[] args) {
  29. String computerName = System.getenv("COMPUTERNAME"); // 컴퓨터 이름 가져오기
  30. String licenseKey = generateLicenseKey(computerName);
  31. System.out.println("Generated license key for " + computerName + ": " + licenseKey);
  32. // Validate the license key
  33. boolean isValid = validateLicenseKey(computerName, licenseKey);
  34. System.out.println("License key is valid: " + isValid);
  35. }
  36. }