Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO: Use the CryptoLicensing Generator API to integrate your license generation, sales/e-commerce and order-fulfillment process

 
Subscribe to the RSS feed for this forum  Forum Index -> CryptoLicensing For .Net
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Thu May 28, 2009 10:34 am    Post subject: HOWTO: Use the CryptoLicensing Generator API to integrate your license generation, sales/e-commerce and order-fulfillment process

The CryptoLicensing Generator API can be used to achieve any level of customization and integration in your license generation, sales/e-commerce and order-fulfillment process. One scenario in which it can be used is to automatically generate and send licenses to the customer via email when the order is placed. To achieve this you need to create a web page which uses the CryptoLicensing Generator API to generate licenses. Then have your credit card gateway or order processor (such as Shareit, Paypal, etc) POST to this page whenever an order is received.

The following sample code shows how to use the CryptoLicensing Generator API to generate licenses using HTTP POST parameters. This sample accepts three POST parameters: the profile name, the userdata to be embedded in the licenses and the machine code if a machine-locked license is to be generated:

Code:
using LogicNP.CryptoLicensing;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get profile, userdata and machinecode from POST params
        string profile = Request.Params["profile"];
        string userData = Request.Params["userdata"];
        string machineCode = Request.Params["machinecode"];

        // Send back generated license
        Response.ContentType = "text/plain";
        string lic = GenerateLicense(profile,userData,machineCode);
        Response.Write(lic);
       
        // alternately send the generated license to the customer via email
    }

    string GenerateLicense(string profile,string userData,string machineCode)
    {
        // Create generator from license project file
        CryptoLicenseGenerator gen = new CryptoLicenseGenerator(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\net.netlicproj"));

        // Load a profile if specified
        if (!string.IsNullOrEmpty(profile))
        {
            // Generating license will have same settings as specified by profile
            gen.SetActiveProfile(profile);

            // If profile specifies that it has userdata, set the user data
            if (gen.HasUserData && !string.IsNullOrEmpty(userData))
                gen.UserData = userData;

            // if the profile specifies that it generates a machine-locked license, set the machine code
            if (gen.HasMachineCode && !string.IsNullOrEmpty((machineCode)))
                gen.MachineCodeAsString = machineCode;
        }
        else
        {
            // No profile specified, you don't need to select a profile anyway (profiles are just pre-defined..
            // license settings which allow you to quickly generate licenses having those settings)

            // Set user data of license
            if (!string.IsNullOrEmpty(userData))
                gen.UserData = userData;

            // If a machine code is specified, set it to generate a machine locked license
            if (!string.IsNullOrEmpty((machineCode)))
                gen.MachineCodeAsString = machineCode;
        }

        // Generate the license with the above settings
        string lic = gen.Generate();

        return lic;

    }
}


[VB.Net]
Code:
Partial Public Class _Default
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    ' Get profile, userdata and machinecode from POST params
    Dim userProfile As String = Request.Params("profile")
    Dim userData As String = Request.Params("userdata")
    Dim machineCode As String = Request.Params("machinecode")

    ' Send back generated license
    Response.ContentType = "text/plain"
    Dim lic As String = GenerateLicense(userProfile, userData, machineCode)
    Response.Write(lic)

    ' alternately send the generated license to the customer via email
  End Sub
 
  Function GenerateLicense(ByVal userProfile As String, ByVal userData As String, ByVal machineCode As String) As String
    ' Create generator from license project file
    Dim gen As CryptoLicenseGenerator = New CryptoLicenseGenerator(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\net.netlicproj"))

    ' Load a profile if specified
    If (Not String.IsNullOrEmpty(userProfile)) Then
        ' Generating license will have same settings as specified by profile
        gen.SetActiveProfile(userProfile)

        ' If profile specifies that it has userdata, set the user data
        If (gen.HasUserData And Not String.IsNullOrEmpty(userData)) Then
            gen.UserData = userData
        End If

        ' If the profile specifies that it generates a machine-locked license, set the machine code
        If (gen.HasMachineCode And Not String.IsNullOrEmpty((machineCode))) Then
            gen.MachineCodeAsString = machineCode
        End If
    Else
        ' No profile specified, you don't need to select a profile anyway (profiles are just pre-defined..
        ' license settings which allow you to quickly generate licenses having those settings)

        ' Set user data of license
        If (Not String.IsNullOrEmpty(userData)) Then
            gen.UserData = userData
        End If

        ' If a machine code is specified, set it to generate a machine locked license
        If (Not String.IsNullOrEmpty((machineCode))) Then
            gen.MachineCodeAsString = machineCode
        End If
        End If
        ' Generate the license with the above settings
    Dim lic As String = gen.Generate()

    Return lic

  End Function

End Class


Notes

The page needs to reference the LogicNP.CryptoLicensing.Generator.dll assembly and needs the license project file which is used to generate licenses against.

Most credit card gateways and order processors allow you to customize the POST parameters to be passed to the web page. They support passing a variety of information about the order including customer name, email, phone number, address, date, product name, etc You can modify the above code to look for the appropriate parameters and to combine the various 'customer-data' parameters such as the name, mail, etc into one 'user-data' string to be embedded in the license.
Back to top
Display posts from previous:   
Forum Index -> CryptoLicensing For .Net All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group