Create License Keys (on your side):
Function GenerateLicenseKey(buyerName As String) As String
Var secretKey As String = "MySuperSecretKey123" // never share this
Var baseString As String = buyerName.Trim + secretKey
// SHA1 creates a 40-character hash
Var hash As String = Crypto.Hash(baseString, Crypto.HashAlgorithms.SHA1)
// Optionally format for readability
Return Uppercase(Mid(hash, 1, 5) + "-" + Mid(hash, 6, 5) + "-" + Mid(hash, 11, 5))
End Function
Validate the License Key (In Your App)
Function IsLicenseValid(buyerName As String, licenseKey As String) As Boolean
Var expectedKey As String = GenerateLicenseKey(buyerName)
Return licenseKey.Trim.Uppercase = expectedKey
End Function
[Optional] Lock the License to a Machine
Function GetMachineID() As String
// Try to uniquely identify the machine
Var info As String = SystemInformation.ComputerName + SystemInformation.Username
Return Crypto.Hash(info, Crypto.HashAlgorithms.SHA1)
End Function
When generating the license for the customer, you’d need their machineID
.
You can build a tiny tool for them that gives you that.
Then change your GenerateLicenseKey()
like this:
Function GenerateLicenseKey(buyerName As String, machineID As String) As String
Var secretKey As String = "MySuperSecretKey123"
Var baseString As String = buyerName.Trim + machineID + secretKey
Var hash As String = Crypto.Hash(baseString, Crypto.HashAlgorithms.SHA1)
Return Uppercase(Mid(hash, 1, 5) + "-" + Mid(hash, 6, 5) + "-" + Mid(hash, 11, 5))
End Function
Example Usage:
Var buyerName As String = "Alice Smith"
Var licenseKey As String = "F3A2C-1AB34-9EDCC"
If IsLicenseValid(buyerName, licenseKey) Then
MessageBox("Thank you! License activated.")
Else
MessageBox("Invalid license key.")
End If
Feature | This Setup |
---|---|
Offline activation | ![]() |
Simple for user | ![]() |
Tied to user | ![]() |
Tied to machine | ![]() |
Hard to crack | ![]() |