Marco28
Posts: 16
Joined: Fri Sep 15, 2017 6:14 am

Generating license for trial

I want to create a small application that generates a license key for a trial version. I took the code form here https://www.advancedinstaller.com/user- ... e-net.html as a start but when I generate the license the signature I get is different then the one generated by Advanced Installer.
The license is based on the Computer Id, License Id (e-mail address) and an expiration date.
The method that generates the license looks like

Code: Select all

public static string  GetLicenseKey(string computerId, string licenseId, DateTime expirationDate)
{
    var data = new StringBuilder();
    var date = expirationDate.ToString("MM/dd/yyyy");
    if (computerId != null) data.Append($"COMP_ID={computerId}ID={licenseId}EXP={date}");

    var sPrivateKeyPEM = File.ReadAllText(@"c:\temp\key.pem");
    var rsaProvider = GetRSA(sPrivateKeyPEM);

    // compute signature
    var dataToSign = Encoding.Unicode.GetBytes(data.ToString());
    var signature = rsaProvider.SignData(dataToSign, new SHA1CryptoServiceProvider());

    // Step 4 - Respond with the license elements
    // if your license has a Maintainance Plan element (or any other elements) add them in alphabetical order
    var license = "ID=" + licenseId + ";EXP=" + date + ";SIGN=" + Convert.ToBase64String(signature);

    return license;
}
Can you please tell me what I am missing?

Kind regards,
Marco
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Generating license for trial

Hello Marco,

This could happen because you are not building the "data" string correctly. Please note that when computing the digital license signature the license elements must be appended to the computed string in alphabetical order.

So, could you please append to your "data" string the license elements in the following order: COMP_ID,EXP and ID and see how this worked?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Marco28
Posts: 16
Joined: Fri Sep 15, 2017 6:14 am

Re: Generating license for trial

Hi Daniel,

I did what you described, but that did not help. I simplified the signature by only using ID, but that did not help. Here is a step by step description of what I did for this;
- Export the private key from the Trial Registration Tab via Actions --> Export PEM...
- Read this file from disk.
- Provide the data ID=1

I compare the result with the value from Advanced Installer via
- "Generate Registration Keys" rom the Trial Registration Tab.
- Enter 1 in the ID field (License ID).

The signatures I get back are different in this case.
I think I did everything as described, but it might be that I missed something.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Generating license for trial

Hello Marco,

Would you be able to try to replicate the behavior in a small buildable sample and send it us by email to support at advancedinstaller dot com alongside a small test case so we can test and investigate this?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Generating license for trial

Hello Marco,

Thank you for your sent sample.

After further investigating your .Net sample application I can say your app is correctly implemented in what regards the license digital signature computation. The confusion was created by the fact that you left the "License Server -> Server URL" field empty in your Advanced Installer setup project.

When the above field is empty (offline registration only) our application uses a different algorithm to merge the license elements (data license string) before computing the license signature. This is why you get a different result when testing the license generate operation within Advanced Installer. So, to perform the test you should first fill an HTTP address in the "Server URL" field and then use our "Generate Registration Keys" option.

Here are the steps to use:

1. open the setup project (.AIP file) in Advanced Installer
2. go to "Licensing" page -> "Trial" -> "Registration" tab
3. fill in an HTTP address in the "Server URL" field
4. use the "Generate Registration Keys" hyperlink

Let us know if this worked.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Marco28
Posts: 16
Joined: Fri Sep 15, 2017 6:14 am

Re: Generating license for trial

Sorry for the late reply, but the solution you provided did the trick.
Thanks!
Catalin
Posts: 6584
Joined: Wed Jun 13, 2018 7:49 am

Re: Generating license for trial

You're welcome, Marco!

We're glad you got this working!

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”