Class Helpers
Helper methods to ease interaction with Web API 3. These methods require .NET Framework 4.0 or 4.6.
Inherited Members
Namespace: SKM.V3.Methods
Assembly: Cryptolens.Licensing.CrossPlatform.dll
Syntax
public static class Helpers
Properties
| Edit this page View SourceWindowsOnly
Only set this setting if you plan to target Windows only. It's only necessary in rare cases. If you have any questions, please contact support@cryptolens.io.
Declaration
public static bool WindowsOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceComputePasswordHash(string)
Computes a string hash of a password using PBKDF2. Note, in comparison to using hash algorithms such as SHA256, the algorithm used in this method slows down the computation on purpose, to make sure it is harder to guess the original password.
Declaration
public static string ComputePasswordHash(string password)
Parameters
| Type | Name | Description |
|---|---|---|
| string | password |
Returns
| Type | Description |
|---|---|
| string |
ComputePasswordHash(string, byte[])
Computes a string hash of a password using PBKDF2. Note, in comparison to using hash algorithms such as SHA256, the algorithm used in this method slows down the computation on purpose, to make sure it is harder to guess the original password.
Declaration
public static string ComputePasswordHash(string password, byte[] salt = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | password | |
| byte[] | salt |
Returns
| Type | Description |
|---|---|
| string |
GetAssemblyHash()
Computes the method of the entry assembly. This method is intended to be
called from an SDK that you want to protect. The "Entry Assembly" is the
first assembly that leads to a method being called in your SDK.
Normally, if a customer uses your SDK in an assembly A, this method will compute the hash/fingerprint of that assembly. If they have developed two assemblies, where the A uses B and B uses your SDK (which calls this method), i.e. A -> B -> SDK, then the hash is computed of the first assembly, i.e. A.
Declaration
public static AssemblySignature GetAssemblyHash()
Returns
| Type | Description |
|---|---|
| AssemblySignature | An AssemblySignature or null if the file cannot be found and/or cannot be read. |
GetAssemblyHash(string)
Computes the method of the entry assembly. This method is intended to be
called from an SDK that you want to protect. The "Entry Assembly" is the
first assembly that leads to a method being called in your SDK.
Normally, if a customer uses your SDK in an assembly A, this method will compute the hash/fingerprint of that assembly. If they have developed two assemblies, where the A uses B and B uses your SDK (which calls this method), i.e. A -> B -> SDK, then the hash is computed of the first assembly, i.e. A.
Declaration
public static AssemblySignature GetAssemblyHash(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Allows you to specify a custom path of the assembly to sign. If null, the default assembly will be signed, as described in the summary. |
Returns
| Type | Description |
|---|---|
| AssemblySignature | An AssemblySignature or null if the file cannot be found and/or cannot be read. |
GetFloatingLicenseInformation(ActivateModel, KeyInfoResult)
Returns floating license related information.
Declaration
public static FloatingLicenseInformation GetFloatingLicenseInformation(ActivateModel activationModel, KeyInfoResult activationResult)
Parameters
| Type | Name | Description |
|---|---|---|
| ActivateModel | activationModel | |
| KeyInfoResult | activationResult |
Returns
| Type | Description |
|---|---|
| FloatingLicenseInformation |
GetFloatingLicenseInformation(int, int, int)
Returns floating license related information.
Declaration
public static FloatingLicenseInformation GetFloatingLicenseInformation(int MaxOverdraft, int MaxNoOfMachines, int UsedFloatingMachines)
Parameters
| Type | Name | Description |
|---|---|---|
| int | MaxOverdraft | |
| int | MaxNoOfMachines | |
| int | UsedFloatingMachines |
Returns
| Type | Description |
|---|---|
| FloatingLicenseInformation |
GetHardiskId()
An alternative way to compute the machine code by relying on the Hardisk Id (assigned by the manufacturer). This is different from Volume Id. Please note: although based on our testing, it should run without admin access, this might not be the case on some machines. Furthermore, this method is specific to Windows and cannot be used on other platforms.
Declaration
public static string GetHardiskId()
Returns
| Type | Description |
|---|---|
| string |
GetMACAddress()
Computes the MAC address, which can be used as a way to identify a machine uniquely.
Declaration
public static string GetMACAddress()
Returns
| Type | Description |
|---|---|
| string |
GetMachineCode(bool, int)
Returns the machine code of the current device with SHA-256 as the hash function. This method works differently depending on the binaries that you use. By default, machine code is computed using COM, which requires System.Management. This is only supported on Windows, it's better to set platformIndependent=true. If you use a version of library without System.Management, the platform independent machine code will be computed by default.
The supported platforms are Windows, Mac and Linux. Note, sudo access is required if Linux is used.
In newer projects, we recommend to always set platformIndependent=true or use GetMachineCodePI().
If version is set to 2, you can get the machine code as in the Python client, assuming similar settings are used. You can read more about it here: https://help.cryptolens.io/faq/index#machine-code-generation
Declaration
public static string GetMachineCode(bool platformIndependent = false, int v = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | platformIndependent | |
| int | v |
Returns
| Type | Description |
|---|---|
| string |
GetMachineCodePI()
Computes a platform independent machine code that works on Windows, Linux and Mac and does not require System.Management.
Note: On Linux, sudo access is necessary.
Declaration
public static string GetMachineCodePI()
Returns
| Type | Description |
|---|---|
| string |
GetMachineCodePI(int)
Computes a platform independent machine code that works on Windows, Linux and Mac and does not require System.Management.
Note: On Linux, sudo access is necessary.
If version is set to 2, you can get the machine code as in the Python client, assuming similar settings are used. You can read more about it here: https://help.cryptolens.io/faq/index#machine-code-generation
Declaration
public static string GetMachineCodePI(int v = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | v |
Returns
| Type | Description |
|---|---|
| string |
GetOSStats()
Creates a JSON dictionary of the type MachineInfo, which contains OSVersion, OSName and Is64Bit (not available in NET 3.5).
Declaration
public static string GetOSStats()
Returns
| Type | Description |
|---|---|
| string | A string representation of the JSON dictionary. |
GetPlatform()
Declaration
public static Helpers.OSType GetPlatform()
Returns
| Type | Description |
|---|---|
| Helpers.OSType |
HasFeature(LicenseKey, int)
Checks so that a certain Feature is enabled (i.e. it's set to TRUE).
Declaration
public static bool HasFeature(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 |
|---|---|
| bool | A key information object if the condition is satisfied. Null otherwise. |
HasFeature(LicenseKey, string)
Uses a special data object associated with the license key to determine if a certain feature exists (instead of the 8 feature flags).
Formatting: The name of the data object should be 'cryptolens_features' and it should be structured as a JSON array.
For example,
["f1", "f2"]
means f1 and f2 are true. You can also have feature bundling, eg.
["f1", ["f2",["voice","image"]]]
which means that f1 and f2 are true, as well as f2.voice and f2.image. You can set any depth, eg. you can have
["f1", ["f2",[["voice",["all"]], "image"]]]
means f2.voice.all is true as well as f2.voice and f2. The dots symbol is used to specify the "sub-features".
Read more here: https://help.cryptolens.io/web-interface/feature-templates
Declaration
public static bool HasFeature(LicenseKey licenseKey, string featureName)
Parameters
| Type | Name | Description |
|---|---|---|
| LicenseKey | licenseKey | The license key |
| string | featureName | For example, "f2.voice.all". |
Returns
| Type | Description |
|---|---|
| bool |
IsOnRightMachine(LicenseKey, bool, bool, bool)
Checks if the current license key is on the correct device with SHA-256 as the hash function.
Declaration
public static bool IsOnRightMachine(LicenseKey licenseKey, bool isFloatingLicense = false, bool allowOverdraft = false, bool platformIndependent = false)
Parameters
| Type | Name | Description |
|---|---|---|
| LicenseKey | licenseKey | The license key object. |
| 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. |
| bool | platformIndependent | Allows you to specify if you want to use the old machine code method that is based on COM and requires System.Management or use the new platform independent method, i.e. GetMachineCodePI(). |
Returns
| Type | Description |
|---|---|
| bool |
IsOnRightMachine(LicenseKey, string, bool, bool)
Checks if the current license key is on the correct device with SHA-256 as the hash function.
Declaration
public static bool IsOnRightMachine(LicenseKey licenseKey, string machineCode, bool isFloatingLicense = false, bool allowOverdraft = false)
Parameters
| Type | Name | Description |
|---|---|---|
| LicenseKey | licenseKey | The license key object. |
| string | machineCode | A unique identifier of the machine. |
| 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 |
|---|---|
| bool |
IsOnRightMachinePI(LicenseKey, bool, bool, int)
Checks if the current license key is on the correct device with SHA-256 as the hash function.
Declaration
public static bool IsOnRightMachinePI(LicenseKey licenseKey, bool isFloatingLicense = false, bool allowOverdraft = false, int v = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| LicenseKey | licenseKey | The license key object. |
| 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. |
| int | v | If version is set to 2, you can get the machine code as in the Python client, assuming similar settings are used. You can read more about it here: https://help.cryptolens.io/faq/index#machine-code-generation |
Returns
| Type | Description |
|---|---|
| bool |
IsSuccessful(BasicResult)
Checks if the result obtained from an API call is successful.
Declaration
public static bool IsSuccessful(BasicResult result)
Parameters
| Type | Name | Description |
|---|---|---|
| BasicResult | result |
Returns
| Type | Description |
|---|---|
| bool |
IsVM()
This method can help to detect if the application is running inside a virtual machine. It has been tested in Microsoft Hyper-V. Support for other VM applications is coming soon.
Declaration
public static bool IsVM()
Returns
| Type | Description |
|---|---|
| bool |
VerifyPassword(LicenseKey, string, string)
This method verifies the username and password with the information in the LicenseKey object. It provides a way to activate a license on a per user rather than per machine basis. To compute the password, the ComputePasswordHash(string) is used. A tutorial on how everything can be set up is available here: https://help.cryptolens.io/licensing-models/user-based-activations
Declaration
public static bool VerifyPassword(LicenseKey license, string username, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| LicenseKey | license | |
| string | username | |
| string | password |
Returns
| Type | Description |
|---|---|
| bool |
VerifySDKLicenseCertificate(string)
Verifies that the certificate of the software using the SDK is valid. This method will use GetAssemblyHash() to compute the hash of the assembly. The entry assembly will be verified, in other words, the assembly that initiated the call first.
Declaration
public static LicenseKey VerifySDKLicenseCertificate(string RSAPubKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | RSAPubKey | Your RSA Public Key, which can be found here: https://app.cryptolens.io/docs/api/v3/QuickStart |
Returns
| Type | Description |
|---|---|
| LicenseKey | License Key object if the certificate is valid and null otherwise. |
VerifySDKLicenseCertificate(string, string, string)
Verifies that the certificate of the software using the SDK is valid. This method will use GetAssemblyHash() to compute the hash of the assembly. The entry assembly will be verified, in other words, the assembly that initiated the call first.
Declaration
public static LicenseKey VerifySDKLicenseCertificate(string RSAPubKey, string certificate, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | RSAPubKey | Your RSA Public Key, which can be found here: https://app.cryptolens.io/docs/api/v3/QuickStart |
| string | certificate | The name of the certificate. Do not add .skm extension, it will be added automatically. |
| string | path | The path to the certificate and the assembly, whose hash is signed. Note, they need to be in the same folder. |
Returns
| Type | Description |
|---|---|
| LicenseKey | License Key object if the certificate is valid and null otherwise. |