123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Security.Cryptography;
- using System.Text;
- public class LicenseManager
- {
- private const string SecretKey = "YourSecretKey"; // 시크릿 키
- public static string GenerateLicenseKey(string computerName)
- {
- using (var sha1 = new SHA1Managed())
- {
- var inputBytes = Encoding.UTF8.GetBytes(computerName + SecretKey);
- var hashBytes = sha1.ComputeHash(inputBytes);
- return BitConverter.ToString(hashBytes).Replace("-", "");
- }
- }
- public static bool ValidateLicenseKey(string computerName, string licenseKey)
- {
- return licenseKey == GenerateLicenseKey(computerName);
- }
- }
- class Program
- {
- static void Main()
- {
- var computerName = Environment.MachineName; // 컴퓨터 이름 가져오기
- var licenseKey = LicenseManager.GenerateLicenseKey(computerName);
- Console.WriteLine($"Generated license key for {computerName}: {licenseKey}");
- // Validate the license key
- var isValid = LicenseManager.ValidateLicenseKey(computerName, licenseKey);
- Console.WriteLine($"License key is valid: {isValid}");
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <License>
- <UserName>JohnDoe</UserName>
- <ExpirationDate>2024-12-31</ExpirationDate>
- <!-- 기타 라이센스 정보 필드 추가 -->
- </License>
- using System;
- using System.IO;
- using System.Xml.Linq;
- public class LicenseManager
- {
- private const string LicenseFilePath = "license.xml"; // 라이센스 파일 경로
- public static bool ValidateLicense()
- {
- try
- {
- var xml = XDocument.Load(LicenseFilePath);
- var userName = xml.Root.Element("UserName")?.Value;
- var expirationDateStr = xml.Root.Element("ExpirationDate")?.Value;
- if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(expirationDateStr))
- {
- Console.WriteLine("Invalid license format.");
- return false;
- }
- if (!DateTime.TryParse(expirationDateStr, out var expirationDate))
- {
- Console.WriteLine("Invalid expiration date format.");
- return false;
- }
- // 여기에서 라이센스 검증 로직을 추가하세요
- // 예: 유효 기간, 사용자 정보, 기타 조건 확인
- return true; // 유효한 라이센스인 경우
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error validating license: {ex.Message}");
- return false; // 라이센스 검증 실패
- }
- }
- }
- class Program
- {
- static void Main()
- {
- if (LicenseManager.ValidateLicense())
- {
- Console.WriteLine("License is valid. Starting the program...");
- // 프로그램 기동 로직 추가
- }
- else
- {
- Console.WriteLine("Invalid license. Program will not start.");
- // 프로그램 정지 로직 추가
- }
- }
- }
|