12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import java.nio.charset.StandardCharsets;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- public class LicenseManager {
- private static final String SECRET_KEY = "YourSecretKey"; // 시크릿 키
- public static String generateLicenseKey(String computerName) {
- try {
- MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
- byte[] inputBytes = (computerName + SECRET_KEY).getBytes(StandardCharsets.UTF_8);
- byte[] hashBytes = sha1.digest(inputBytes);
- StringBuilder hexString = new StringBuilder();
- for (byte hashByte : hashBytes) {
- String hex = Integer.toHexString(0xff & hashByte);
- if (hex.length() == 1) {
- hexString.append('0');
- }
- hexString.append(hex);
- }
- return hexString.toString();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- return null;
- }
- }
- public static boolean validateLicenseKey(String computerName, String licenseKey) {
- return licenseKey.equals(generateLicenseKey(computerName));
- }
- public static void main(String[] args) {
- String computerName = System.getenv("COMPUTERNAME"); // 컴퓨터 이름 가져오기
- String licenseKey = generateLicenseKey(computerName);
- System.out.println("Generated license key for " + computerName + ": " + licenseKey);
- // Validate the license key
- boolean isValid = validateLicenseKey(computerName, licenseKey);
- System.out.println("License key is valid: " + isValid);
- }
- }
|