Using LexActivator with VB.NET

Adding licensing to your app

After you've added a product for your app in the dashboard, go to the product page of the product you will be adding licensing to. You will need to do three things:

  • Note the product id for the product.

  • Download the Product.dat for the product.

  • Download the example project from Github

Product.dat contains product data which is used by LexActivator. Product id is the identifier of your product which is to be used in the code.

Adding library to your app

LexActivator wrapper for VB.NET can be easily installed through nuget:

Install-Package Cryptlex.LexActivator

LexActivator has dependency on VS2015 runtime on Windows. On the target machines where you will deploy your app, you can install the VS2015 runtime, if not present, using the link: https://www.microsoft.com/en-in/download/details.aspx?id=48145

LexActivator (.NET Core) has dependency on libnss3 library on Linux. On the target machines where you will deploy your app, ensure libnss3 library is installed.

Setting product.dat file and product Id

The first thing you need to do is either embed the Product.dat file in your app using SetProductData() function or set the absolute path of the file using SetProductFile() function.

The next thing you need to do is to set the product id of your application in your code using SetProductId() function. It sets the id of the product you will be adding licensing to.

LexActivator.SetProductData("PASTE_CONTENT_OF_PRODUCT.DAT_FILE");
LexActivator.SetProductId("PASTE_PRODUCT_ID", LexActivator.PermissionFlags.LA_USER);

If your app requires admin (root) privileges to run (e.g. services, daemons etc.), instead of passing LexActivator.PermissionFlags.LA_USER flag, you need to pass LexActivator.PermissionFlags.LA_SYSTEM flag.

In case your app doesn't have write access to the disk, you can use LexActivator.PermissionFlags.LA_IN_MEMORY flag instead, which causes all the data to be stored in the memory. But this would require you to activate the license every time you restart the app.

License activation

To activate the license in your app using the license key, you will use ActivateLicense() LexActivator API function. It invokes the /v3/activations Cryptlex Web API endpoint, verifies the encrypted and digitally signed response to validate the license.

Private Sub activateLicenseBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim status As Integer
LexActivator.SetLicenseKey(productKeyBox.Text)
LexActivator.SetActivationMetadata("key1", "value1")
status = LexActivator.ActivateLicense()
If status = LexStatusCodes.LA_OK OrElse status = LexStatusCodes.LA_EXPIRED OrElse status = LexStatusCodes.LA_SUSPENDED Then
Me.statusLabel.Text = "Activation Successful :" & status.ToString()
Me.activateBtn.Text = "Deactivate"
Me.activateTrialBtn.Enabled = False
Else
Me.statusLabel.Text = "Error activating the license: " & status.ToString()
End If
Catch ex As LexActivatorException
Me.statusLabel.Text = "Error code: " & ex.Code.ToString() & " Error message: " + ex.Message
End Try
End Sub

The above code should be executed at the time of license activation.

Verifying license activation

Each time, your app starts, you need to verify whether your license is already activated or not. This verification should occur locally by verifying the cryptographic digital signature of activation. Ideally, it should also asynchronously contact Cryptlex servers to validate and sync the license activation periodically. For this you need to use IsLicenseGenuine() LexActivator API function.

Public Sub New()
InitializeComponent()
Try
LexActivator.SetProductData("PASTE_CONTENT_OF_PRODUCT.DAT_FILE")
LexActivator.SetProductId("PASTE_PRODUCT_ID", LexActivator.PermissionFlags.LA_USER)
Dim status As Integer = LexActivator.IsLicenseGenuine()
If status = LexStatusCodes.LA_OK OrElse status = LexStatusCodes.LA_EXPIRED OrElse status = LexStatusCodes.LA_SUSPENDED OrElse status = LexStatusCodes.LA_GRACE_PERIOD_OVER Then
Me.statusLabel.Text = "License genuinely activated! Activation Status: " & status.ToString()
Else
Me.statusLabel.Text = "License is not activated: " & status.ToString()
End If
Catch ex As LexActivatorException
Me.statusLabel.Text = "Error code: " & ex.Code.ToString() & " Error message: " + ex.Message
End Try
End Sub

The above code should be executed every time user starts the app. After verifying locally, it schedules a periodic server check in a separate thread.

Need more help

In case you need more help for adding LexActivator to your app, we'll be glad to help you make the integration. You can either post your questions on our support forum or can contact us through email.