Class ExtensionMethods
The extension methods are not thought to be used through this class, but instead through the relevant objects that they affect. Please see the examples below.
Inherited Members
Namespace: SKMV3
Assembly: Cryptolens.Licensing.CrossPlatform.dll
Syntax
public static class ExtensionMethods
Examples
// assuming license is a LicenseKey object.
if(license.HasFeature(1)
.HasNotExpired()
.IsValid())
{
// do something
}
else
{
// invalid license.
}
Methods
| Improve this Doc View SourceContains(List<DataObject>, string)
Checks if the list contains an object with a specific name.
Declaration
public static bool Contains(this List<DataObject> dataObjects, string name)
Parameters
Type | Name | Description |
---|---|---|
ListDataObject | dataObjects | |
string | name | The name of the data object |
Returns
Type | Description |
---|---|
bool | True if the data object with the specific name exists and false otherwise. |
Get(List<DataObject>, string)
Returns a data object with the specified name.
Declaration
public static DataObject Get(this List<DataObject> dataObjects, string name)
Parameters
Type | Name | Description |
---|---|---|
ListDataObject | dataObjects | |
string | name | The name of the data object |
Returns
Type | Description |
---|---|
DataObject | The data object if the data object with the specific name exists and null otherwise. |
HasFeature(LicenseKey, int)
Checks so that a certain Feature is enabled (i.e. it's set to TRUE).
Declaration
public static LicenseKey HasFeature(this LicenseKey licenseKey, int featureNumber)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
int | featureNumber | The feature number, eg. feature1, feature 2, etc. FeatureNumber can be 1,2,...,8. |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
HasNotExpired(LicenseKey, bool, bool)
Checks that they key has not expired (i.e. the expire date has not been reached).
Declaration
public static LicenseKey HasNotExpired(this LicenseKey licenseKey, bool checkWithInternetTime = false, bool allowUsagOnExpirationDate = true)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
bool | checkWithInternetTime | If set to true, we will also check that the local time (on the client computer) has not been changed (using SKM.TimeCheck). |
bool | allowUsagOnExpirationDate | If set to true, the user will not be able to use the license on the expiration date (i.e. null will be returned on the expiration date). |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
Remarks
This method might still return a license key (meaning it has not expired) on the next day of the expiration date.
For example, if a license key was created 15:00 UTC on Monday, then it will continue to work on Tuesday until 15:00 UTC.
This behavior can be prevented by setting allowUsagOnExpirationDate
to False.
HasNotFeature(LicenseKey, int)
Checks so that a certain Feature is disabled (i.e. it's set to FALSE).
Declaration
public static LicenseKey HasNotFeature(this LicenseKey licenseKey, int featureNumber)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
int | featureNumber | The feature number, eg. feature1, feature 2, etc. FeatureNumber can be 1,2,...,8. |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
HasValidSignature(LicenseKey, string)
Checks that this object has a valid signature, which means that the content has not been altered after that it was generated by Cryptolens.
Declaration
public static LicenseKey HasValidSignature(this LicenseKey licenseKey, string rsaPublicKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | rsaPublicKey | The public key (RSA). It can be found here: https://app.cryptolens.io/User/Security |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
HasValidSignature(LicenseKey, string, int?)
Checks that this object has a valid signature, which means that the content has not been altered after that it was generated by Cryptolens.
Declaration
public static LicenseKey HasValidSignature(this LicenseKey licenseKey, string rsaPublicKey, int? signatureExpirationInterval)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | rsaPublicKey | The public key (RSA). It can be found here: https://app.cryptolens.io/User/Security |
int | signatureExpirationInterval | If the license key was signed, this method will check so that no more than "signatureExpirationInterval" days have passed since the last activation. |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
IsBlocked(LicenseKey)
Checks so that a they key is blocked.
Declaration
public static LicenseKey IsBlocked(this LicenseKey licenseKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
IsNotBlocked(LicenseKey)
Checks so that a they key is not blocked.
Declaration
public static LicenseKey IsNotBlocked(this LicenseKey licenseKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey |
Returns
Type | Description |
---|---|
LicenseKey | A key information object if the condition is satisfied. Null otherwise. |
IsOnRightMachine(LicenseKey, bool, bool)
Checks so that the machine code corresponds to the machine code of this computer. The default hash function is SHA1.
Declaration
public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, bool isFloatingLicense = false, bool allowOverdraft = false)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
bool | isFloatingLicense | |
bool | allowOverdraft | If floating licensing is enabled with overdraft, this parameter should be set to true. You can enable overdraft by setting MaxOverdraft to a value greater than 0. |
Returns
Type | Description |
---|---|
LicenseKey |
Remarks
Please use SKM.V3.Methods.Helpers.IsOnRightMachine(LicenseKey) instead of this method since it uses SHA256 by default.
IsOnRightMachine(LicenseKey, Func<string, string>, bool, bool)
Checks so that the machine code corresponds to the machine code of this computer.
Declaration
public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, Func<string, string> hashFunction, bool isFloatingLicense = false, bool allowOverdraft = false)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
Funcstringstring | hashFunction | A hash function used to hash the current computer's parameters. |
bool | isFloatingLicense | If this is a floating license, this parameter has to be set to true. You can enable floating licenses by setting FloatingTimeInterval to a value greater than 0. |
bool | allowOverdraft | If floating licensing is enabled with overdraft, this parameter should be set to true. You can enable overdraft by setting MaxOverdraft to a value greater than 0. |
Returns
Type | Description |
---|---|
LicenseKey |
IsOnRightMachine(LicenseKey, string, bool, bool)
Checks so that the machine code corresponds to the machine code of this computer.
Declaration
public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, string machineCode, bool isFloatingLicense = false, bool allowOverdraft = false)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | machineCode | a unique machine identifier |
bool | isFloatingLicense | If this is a floating license, this parameter has to be set to true. You can enable floating licenses by setting FloatingTimeInterval to a value greater than 0. |
bool | allowOverdraft | If floating licensing is enabled with overdraft, this parameter should be set to true. You can enable overdraft by setting MaxOverdraft to a value greater than 0. |
Returns
Type | Description |
---|---|
LicenseKey |
IsValid(LicenseKey)
Checks that the Key Information object is valid (in the correct format). You can always add constraints such as @HasNotExpired(LicenseKey, bool, bool).
Declaration
public static bool IsValid(this LicenseKey licenseKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey |
Returns
Type | Description |
---|---|
bool | Returns true if the object is valid and false otherwise. |
IsValid(LicenseKey, string)
Checks that the Key Information object is valid (in the correct format). You can always add constraints
such as @HasNotExpired(LicenseKey, bool, bool).
It will also check if the license key file has been modified by an unauthorized person.
This method will only return true if the license key information is exactly
the same as the one that was provided and signed by SKM.
Declaration
public static bool IsValid(this LicenseKey licenseKey, string rsaPublicKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | rsaPublicKey | The public key (RSA). It can be found here: https://app.cryptolens.io/User/Security |
Returns
Type | Description |
---|---|
bool | Returns true if the object is valid and false otherwise. |
LoadFromFile(LicenseKey, string, string)
Loads the LicenseKey object from a file.
Declaration
public static LicenseKey LoadFromFile(this LicenseKey licenseKey, string file = "licensekey.skm", string RSAPubKey = null)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | file | The entire path including file name, i.e. c:\folder\file.txt |
string | RSAPubKey |
Returns
Type | Description |
---|---|
LicenseKey | Returns the original object if successful. Null otherwise. |
Remarks
The current object will not be affected. Instead, you need to assign it manually, eg. licenseKey = licenseKey.LoadFromFile().
LoadFromString(LicenseKey, string, string)
Get the license object as a string. Signature verification will occur automatically. Returns a new license key object.
Declaration
public static LicenseKey LoadFromString(this LicenseKey licenseKey, string RSAPubKey, string serializedLicenseObject)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | RSAPubKey | |
string | serializedLicenseObject |
Returns
Type | Description |
---|---|
LicenseKey |
RegisterEvent(LicenseKey, string, Event)
Registers an event related to this license key. Note, this methods only works on the .NET Framework.
Declaration
public static void RegisterEvent(this LicenseKey licenseKey, string token, Event eventObj)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | token | An access token with RegisterEvent permission is required. |
Event | eventObj |
RegisterEvent(LicenseKey, string, Event, string)
Registers an event related to this license key. Note, this methods only works on the .NET Framework. The machine code will be generated using Methods.Helpers.GetMachineCode()
Declaration
public static void RegisterEvent(this LicenseKey licenseKey, string token, Event eventObj, string machineCode)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | token | An access token with RegisterEvent permission is required. |
Event | eventObj | |
string | machineCode |
SaveAsString(LicenseKey)
Get the license object as a string.
Declaration
public static string SaveAsString(this LicenseKey licenseKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey |
Returns
Type | Description |
---|---|
string |
SaveToFile(LicenseKey)
Saves the current LicenseKey object to file.
Declaration
public static LicenseKey SaveToFile(this LicenseKey licenseKey)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey |
Returns
Type | Description |
---|---|
LicenseKey | Returns the original object if successful. Null otherwise. |
SaveToFile(LicenseKey, string)
Saves the current LicenseKey object to file. If you need a guarantee where the file will be saved, please specify an absolute path, e.g. 'C:\licensefile.skm'. If a relative path is specified, it will in most cases be saved in the current directory. The definition of what the current directory is will vary between execution environments.
Declaration
public static LicenseKey SaveToFile(this LicenseKey licenseKey, string file)
Parameters
Type | Name | Description |
---|---|---|
LicenseKey | licenseKey | |
string | file | The entire path including file name, i.e. c:\folder\file.txt |
Returns
Type | Description |
---|---|
LicenseKey | Returns the original object if successful. Null otherwise. |