Skip to content

Instantly share code, notes, and snippets.

@HowardvanRooijen
Last active August 29, 2015 14:16
Show Gist options
  • Save HowardvanRooijen/4eef2e3e0e10b6803c22 to your computer and use it in GitHub Desktop.
Save HowardvanRooijen/4eef2e3e0e10b6803c22 to your computer and use it in GitHub Desktop.
License Generation Code
public static void Main(string[] args)
{
var dataDirectory = @"..\..\..\..\LicenseData".ResolveBaseDirectory();
var publicKeyPath = @"..\..\..\..\LicenseData\PublicKey.xml".ResolveBaseDirectory();
var licensePath = @"..\..\..\..\LicenseData\License.xml".ResolveBaseDirectory();
if (!Directory.Exists(dataDirectory))
{
Directory.CreateDirectory(dataDirectory);
}
var licenseCriteria = new LicenseCriteria
{
ExpirationDate = DateTimeOffset.UtcNow.LastDayOfMonth().EndOfDay(),
IssueDate = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(),
MetaData = new Dictionary<string, string> { { "LicensedCores", "2" } },
Type = "Subscription"
};
var privateKey = new RsaPrivateKeyProvider().Create();
var serverLicense = new ServerLicenseGenerator().Generate(privateKey, licenseCriteria);
var clientLicense = serverLicense.ToClientLicense();
// In a real implementation, you would embed the public key into the assembly, via a resource file
File.WriteAllText(publicKeyPath, privateKey.ExtractPublicKey().Contents);
// In a real implementation you would implement ILicenseRepository
File.WriteAllText(licensePath, clientLicense.Content.InnerXml);
Console.WriteLine(Messsages.LicenseGenerated, dataDirectory);
Console.WriteLine(Messsages.PressAnyKey);
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment