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}"); } } JohnDoe 2024-12-31 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."); // ÇÁ·Î±×·¥ Á¤Áö ·ÎÁ÷ Ãß°¡ } } }