Serial Key Maker API
Introduction
This document describes the various methods an properties on the Serial Key Maker API. It also shows best practice usage for implementing Serial Key Maker's licensing solution into your applications.
The Code
To assist with this documentation, download and unzip the following project files:
VS 2005 [Link] SKM_API_Documentation.zip
VS 2008 [Link] SKM_API_Documentation.zip
Creating a License Object ([Link])
In order to use the Serial Key Maker API, you need to create a valid license object. To do this you need the private password key that was used to create the license keys you want to test. Recall, you create a license key with the Serial Key Maker user interface, you had to enter a private password key.
The Private Password Key needs to travel with your application so that the API can use it to decrypt the License Key. It should therefore be encrypted so that it cannot be easily read. Store it with your app, or in the registry, or in a file that your application can read. You can optionally pass in a logging object that will handle internal error logging for you. You can pass in Nothing or null if you wish. The logging object is discussed below.
C# [Link] objLicenseObject; // --- encrypt this when using a real application. DO NOT hard-code it like this string strPrivateKey = "MyPrIv@t3KeY!#"; [Link]. classLogging objLogging = null; objLicenseObject = new [Link](strPrivateKey, objLogging);
[Link] Dim objLicenseObject As [Link] '--- encrypt this when using a real application. DO NOT hard-code it like this Dim strPrivateKey As String = "MyPrIv@t3KeY!#" Dim objLogging As [Link] = Nothing objLicenseObject = New [Link](strPrivateKey, objLogging)
classLogging ([Link])
The logging object ([Link]) is an internal object that captures and writes log messages for you. Use is optional - you can pass in nothing to the licensing constructor if you do not wish to use it. If you do wish to use it, you must explicitly turn logging on - it is off by default. To create a licensing object, you do the following:
C# [Link] objLogging; // --- create instance of the object, passing in the log path.
// --- if it does not exist it will be created objLogging = new [Link]("c:\\dev\\skmlog\\skm_logging.txt");
[Link] Dim objLogging As [Link] '--- create instance of the object, passing in the log path. '--- if it does not exist it will be created
objLogging = New [Link]("c:\dev\skmlog\skm_logging.txt")
classLogging Properties
LoggingIsEnabled
C# // --- No logging will happen unless this is explicitly enabled // --- DEFAULT: False [Link] = true;
[Link] '--- No logging will happen unless this is explicitly enabled '--- DEFAULT: False [Link] = True
ConsoleIsOn
C# //--- .ConsoleIsOn: passes ALL messages to the console. //--- This includes messages sent to the file. //--- DEFAULT: False [Link] = true;
[Link] '--- .ConsoleIsOn: passes ALL messages to the console. '--- This includes messages sent to the file '--- DEFAULT: False [Link] = True
UseHourlyLoggingFilename
C# //--- .UseHourlyLoggingFilename(): appends the //--- hour to the log file name //--- DEFAULT: True //--- NOTE: Known Bug1: When you disable hourly logging, it also turns off appending the date //--Known Bug2: There is no way to toggle only the date, independent of the time [Link] = false; [Link] '--- .UseHourlyLoggingFilename(): appends the '--- hour to the log file name '--- DEFAULT: True '--- NOTE: Known Bug1: When you disable hourly logging, it also turns off appending the date '--Known Bug2: There is no way to toggle only the date, independent of the time [Link] = False
LogFileExtension
C# //--- .LogFileExtension: ReadOnly. //--- Displays what the current extension is [Link](("Log file extension is: " + [Link]));
[Link] '--- .LogFileExtension: ReadOnly. '--- Displays what the current extension is [Link]("Log file extension is: " & [Link])
LogFileName
C# // --- .LogFileName: ReadOnly. Displays log file name [Link](("Log file name is: " + [Link])); [Link] '--- .LogFileName: ReadOnly. Displays log file name [Link]("Log file name is: " & [Link])
LogPathDirectory
C# // --- .LogPathDirectory: ReadOnly. Display current log folder [Link](("Log folder name is: " + [Link]));
[Link] '--- .LogPathDirectory: ReadOnly. Display current log folder [Link]("Log folder name is: " & [Link])
WholeLogFilePathandName
C# // --- .WholeLogFilePathandName(): Display the entire file and path (including date/time if on) [Link](("WholeLogFilePathandName is " + [Link])); [Link] '--- .WholeLogFilePathandName(): Display the entire file and path (including date/time if on) [Link]("WholeLogFilePathandName is " & [Link])
LocalMachineCode
To use the MachineCode to lock your license key to one particular machine you need to code your application so that it presents the "LocalMachineCode" property to the user in an about box or something similar. Your user then communicates their local machine code to you, and you then use the Serial Key Maker user interface to generate a license key specific to that machine code.
You cannot change the value of LocalMachineCode (it is readonly) as it is generated internally to the Serial Key Maker API. It uses a combination of the machine's MAC address, Video card serial number and hard drive partition serial number to generate a hash.
C# [Link](("The local machine code is: " + p_objLicenseObject.LocalMachineCode));
[Link] [Link]("The local machine code is: " & p_objLicenseObject.LocalMachineCode)
classLogging Methods
LogToConsole
C#
// --- .LogToConsole: Writes to the console [Link]([Link].e_in "This is a test.");
[Link]
'--- .LogToConsole: Writes to the console [Link]([Link].e_int "This is a test.")
LogFilePathandName
C# // --- .LogFilePathandName: WriteOnly. Change the logfile. // --- Needs to be the whole path. [Link] = "c:\\dev\\skmlog\\skm_logging2.txt";
[Link] '--- .LogFilePathandName: WriteOnly. Change the logfile. '--- Needs to be the whole path. [Link] = ("c:\dev\skmlog\skm_logging2.txt")
DeleteLogFile
C# // --- .DeleteLogFile(): Deletes the current logfile // --- causes untrapped runtime error if file does not // --- exist, so trap errors [Link]();
[Link] '--- .DeleteLogFile(): Deletes the current logfile '--- causes untrapped runtime error if file does not '--- exist, so trap errors [Link]()
DeleteLogFolder
C# // --- .DeleteLogFolder(): Deletes the current logfile // --- causes untrapped runtime error if file does not // --- exist, so trap errors [Link]();
[Link] '--- .DeleteLogFolder(): Deletes the current logfile '--- causes untrapped runtime error if file does not '--- exist, so trap errors [Link]()
LogRuntimeError
C# // --- .LogRuntimeError(): Special Logging method to record a to // --record a runtime error // --- Parameters: Source, Message, StackTrace
[Link]("Source Here", "Error Message Here", "StackTrace Here"); [Link] '--- .LogRuntimeError(): Special Logging method to record a to '--- record a runtime error '--- Parameters: Source, Message, StackTrace [Link]("Source Here", "Error Message Here", "StackTrace Here")
classLogging Enumerations
Used for console messages when using the LogToConsole method. [Link].e_intInfo() [Link].e_intError() [Link].e_intNone() [Link].e_intSuccess()
ValidatedKey Object
The ValidatedKey object is the crux of the Serial Key Maker API. It contains the details of the license key supplied to the user, and contains all the data tied to a particular license key. To create a validated key object, you need to (at minimum) pass in a Serial Key Maker generated license key, which is a 20 character string in the following format: THCNT-WIRHO-MOAIF-ITRUS (this is a key generated with the private key:MyPrIv@t3KeY!#, using the Serial Key Maker user interface)
Constructors
There are two overloads to creating a ValidatedKey Object. One is for use without a Machine Code, and the other is for use with the machine code property to tie the license key to the users machine. You will need a valid license object to make a ValidatedKey object.
C# [Link] objValidatedKey;
//--- Overload 1 objValidatedKey = p_objLicenseObject.ValidateKey("THCNT-WIRHO-MOAIFITRUS"); //--- Overload 2 objValidatedKey = p_objLicenseObject.ValidateKey("THCNT-WIRHO-MOAIFITRUS", p_objLicenseObject.LocalMachineCode);
[Link] Dim objValidatedKey As [Link] '--- Overload 1 objValidatedKey = p_objLicenseObject.ValidateKey("THCNT-WIRHO-MOAIFITRUS") '--- Overload 2 objValidatedKey = p_objLicenseObject.ValidateKey("THCNT-WIRHO-MOAIFITRUS", p_objLicenseObject.LocalMachineCode)
ValidatedKey Properties
DateCreated
C# // --- .DateCreated: Display the date the license // --- key was created [Link](("Date Created: " + [Link]));
[Link] '--- .DateCreated: Display the date the license '--- key was created [Link]("Date Created: " & [Link])
DateValidThrough
C# // --- .DateValidThrough: Displays the // --- date the license key expires. [Link](("Date Valid Through: " + [Link])); // --- TIP: Use the "DateValidThrough" property to
// // // //
--- display to your user --- how many days are left of their demo. --- As in: --- Demo Days Left = ([Link] - Today)
[Link](("Days left on your demo: " + [Link]([Link], [Link], [Link],[Link],Microso
[Link] '--- .DateValidThrough: Displays the '--- date the license key expires. [Link]("Date Valid Through: " & [Link]) '--- TIP: '--'--'--Today) Use the "DateValidThrough" property to display to your user how many days are left of their demo. As in: Demo Days Left = ([Link] -
[Link]("Days left on your demo: " & [Link]([Link], [Link], [Link]).ToString)
Expires
C# // --- .Expires: Displays whether the license key expires // --- If it does expire, then you have a DEMO key [Link](("Expires: " + [Link]())); [Link] '--- .Expires: Displays whether the license key expires '--- If it does expire, then you have a DEMO key [Link]("Expires: " & [Link])
Features
C# // --- Features 1 through 5: // --- A license key can embed which features are enable
// --- NOTE: Features are linear. That is, if "Feature 4" is // --- enabled, then features 1 through 3 are enabled too. [Link](("Feature 1 enabled: " + [Link]())); [Link](("Feature 2 enabled: " + [Link]())); [Link](("Feature 3 enabled: " + [Link]())); [Link](("Feature 4 enabled: " + [Link]())); [Link](("Feature 5 enabled: " + [Link]()));
[Link] '--'--'--'--Features 1 through 5: A license key can embed which features are enable NOTE: Features are linear. That is, if "Feature 4" is enabled, then features 1 through 3 are enabled too.
[Link]("Feature 1 enabled: " & [Link]) [Link]("Feature 2 enabled: " & [Link]) [Link]("Feature 3 enabled: " & [Link]) [Link]("Feature 4 enabled: " & [Link]) [Link]("Feature 5 enabled: " & [Link])
FreeformText
You can embed free form text into the license key. If you do, the license key will NOT be a neat 25 character string, but will rather be an encrypted string that contains the text. TIP: You typically supply this key in the form of a file - you cannot expect your user to type it in!
As an example, the following key has some free form text in it, in addition to locking 3 features and being a 300 day demo key:
C# string strLongLicenseKey = "PGieNwikouu28z54lJpOhsodkFZ917nMPw9gzb6uScxjH0M/ NgxVS8rWLvpwRI1enl3hpuQizsZWYqA95FHlYlC1+1rNaCMaJmmqv+m2/ K9ksSCr+55ftFw3Lc0nxDPZhn2E+rQxO/pmJNxBoLDJ6Q=="; objValidatedKey = p_objLicenseObject.ValidateKey(strLongLicenseKey); [Link]([Link]);
[Link] Dim strLongLicenseKey As String = "PGieNwikouu28z54lJpOhsodkFZ917nMPw9gzb6uScxjH0M/ NgxVS8rWLvpwRI1enl3hpuQizsZWYqA95FHlYlC1+1rNaCMaJmmqv+m2/ K9ksSCr+55ftFw3Lc0nxDPZhn2E+rQxO/pmJNxBoLDJ6Q==" objValidatedKey = p_objLicenseObject.ValidateKey(strLongLicenseKey) [Link]([Link])
FreeformTextItems
If you separate individual items in your free form text with the "pipe" character (|), then the API will automatically split it into the FreeformTextItems array.
C# foreach (string itm in [Link]) { intCounter++; [Link](("Item " + ([Link]() + (": " + itm)))); }
[Link] For Each itm As String In [Link] intCounter += 1 [Link]("Item " & [Link] & ": " & itm)
Next
IsCurrentlyValid
Is the key you tested valid?
C# if ([Link]) { [Link]("The license key IS valid."); } else { [Link]("The license key is NOT valid."); } [Link] If [Link] Then [Link]("The license key IS valid.") Else [Link]("The license key is NOT valid.") End If
Key
C# // --- .Key: String - Echo's back the current // --- key that was tested // --- This string does not contain the free form text items etc [Link](("The current license key is: " + [Link])); [Link] '--- .Key: String - Echo's back the current '--- key that was tested '--- This string does not contain the free form text items etc [Link]("The current license key is: " & [Link])
MachineCode
C# // --- .MachineCode: String - The local machine's Machine Code, // --- This is the same value as the LocalMachineCode // --- property of the classLicense object [Link](("The MachineCode key is: " + ([Link] + (" and is the same as the LocalMachineCode: " + p_objLicenseObject.LocalMachineCode)))); [Link] '--- .MachineCode: String - The local machine's Machine Code, '--- This is the same value as the LocalMachineCode '--- property of the classLicense object [Link]("The MachineCode key is: " & [Link] & " and is the same as the LocalMachineCode: " & p_objLicenseObject.LocalMachineCode)
MachineCodeValidates
C# // // // if { --- .MachineCodeValidates: Boolean - Did the local machine --- code validate? --- Will return true if no machine code is used. ([Link]) [Link]("The machine code DOES validate."); } else { [Link]("The machine code DOES NOT validate."); }
[Link] '--- .MachineCodeValidates: Boolean - Did the local machine '--- code validate? '--- Will return true if no machine code is used. If [Link] Then [Link]("The machine code DOES validate.") Else
[Link]("The machine code DOES NOT validate.") End If
PublicKeyValidates
C# // --- .PublicKeyValidates: Boolean // --- Did the public key validate if ([Link]) { [Link]("The public key DOES validate."); } else { [Link]("The public key DOES NOT validate."); }
[Link] '--- .PublicKeyValidates: Boolean '--- Did the public key validate If [Link] Then [Link]("The public key DOES validate.") Else [Link]("The public key DOES NOT validate.) End If
ValidVersion
C# // --- .ValidVersion: String - Reports what the this // --- version of the API valid for this key. [Link](("ValidVersion is " + [Link])); [Link] '--- .ValidVersion: String - Reports what the this '--- version of the API valid for this key. [Link]("ValidVersion is " & [Link])
More Code
For more code samples visit: [Link]