LicenseKey.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace Comal.Classes
  2. {
  3. #if LICENCEENABLED
  4. public class LicenseKey : GlobalConfigurationSettings
  5. {
  6. public String Data { get; set; }
  7. public void Encode(String machineid, DateTime renewed, DateTime expiry)
  8. {
  9. Dictionary<String, String> data = new Dictionary<string, string>();
  10. data["machineid"] = machineid;
  11. data["renewed"] = renewed.ToString("o");
  12. data["expiry"] = expiry.ToString("o");
  13. Data = Encryption.Encrypt(Serialization.Serialize(data), "(!Th3@Qu1ck#Br0wn$F0xJump5%0v3r^th3&L4zy*d0g)");
  14. }
  15. public bool Decode(out string machineid, out DateTime renewed, out DateTime expiry)
  16. {
  17. try
  18. {
  19. String json = Encryption.Decrypt(Data, "(!Th3@Qu1ck#Br0wn$F0xJump5%0v3r^th3&L4zy*d0g)");
  20. var data = Serialization.Deserialize<Dictionary<String, String>>(json);
  21. machineid = data["machineid"];
  22. renewed = data.ContainsKey("renewed") ? DateTime.Parse(data["renewed"]) : DateTime.MinValue;
  23. expiry = DateTime.Parse(data["expiry"]);
  24. return true;
  25. }
  26. catch
  27. {
  28. machineid = "";
  29. renewed = DateTime.MinValue;
  30. expiry = DateTime.MinValue;
  31. }
  32. return false;
  33. }
  34. }
  35. #endif
  36. }