junian / Standard.Licensing

Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and MAUI / Xamarin products
https://junian.dev/Standard.Licensing/
MIT License
554 stars 127 forks source link

Without ExpireAt? #25

Closed SonaBIMDev closed 5 months ago

SonaBIMDev commented 2 years ago

Hi, is it possible to generate a Licence without an ExpiresAt condition? Thx

AntiGuideAkquinet commented 1 year ago

Yes I think you can. I used the example provided in the README and commented out the ExpiresAt, which still produces a XML string.

var passPhrase = "TestPassphrase";

var keyGenerator = Standard.Licensing.Security.Cryptography.KeyGenerator.Create(); 
var keyPair = keyGenerator.GenerateKeyPair();
var privateKey = keyPair.ToEncryptedPrivateKeyString(passPhrase);  
var publicKey = keyPair.ToPublicKeyString();

var license = License.New()  
    .WithUniqueIdentifier(Guid.NewGuid())  
    .As(LicenseType.Trial)  
    //.ExpiresAt(DateTime.Now.AddDays(30))  
    .WithMaximumUtilization(5)  
    .WithProductFeatures(new Dictionary<string, string>  
    {  
        {"Sales Module", "yes"},  
        {"Purchase Module", "yes"},  
        {"Maximum Transactions", "10000"}  
    })  
    .LicensedTo("John Doe", "john.doe@example.com")  
    .CreateAndSignWithPrivateKey(privateKey, passPhrase);

Console.WriteLine(license.ToString());
SonaBIMDev commented 1 year ago

Hi @AntiGuideAkquinet Wow! I didn't believe in it anymore! Thx for sharing!