import hmac import hashlib import json from datetime import datetime, timedelta # This is your master key. NEVER share this or put it in public code. SECRET_KEY = b"mxPIC_Super_Secret_Master_Key_2026!" def generate_license(mac_address: str, days_valid: int, output_file: str = "mxpic.lic"): """Generates a cryptographically signed license file.""" # Calculate the expiration date expiration = (datetime.now() + timedelta(days=days_valid)).strftime("%Y-%m-%d") # Create the payload message we want to sign message = f"{mac_address}|{expiration}".encode('utf-8') # Generate the unforgeable signature using HMAC + SHA256 signature = hmac.new(SECRET_KEY, message, hashlib.sha256).hexdigest() # Create the license dictionary license_data = { "mac_address": mac_address, "expiration": expiration, "signature": signature } # Save to file with open(output_file, "w") as f: json.dump(license_data, f, indent=4) # print(f"✅ License generated for MAC {mac_address}") print(f"✅ Expires on {expiration}") print(f"✅ Saved to {output_file}") if __name__ == "__main__": # Example: Customer sends MAC "A1:B2:C3:D4:E5:F6", they bought a 1-year license generate_license("D4:54:8B:F1:46:49", days_valid=365,output_file="mxpic.lic")