HardwareId

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

A hardware identifier.

public class HardwareId

Inheritance

objectHardwareId

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

HardwareId()

Initializes a new instance of the class.

public HardwareId()

Examples

HardwareId hardwareId = new HardwareId();
string hardwareKey = hardwareId.ToMachineKey();

HardwareId(HardwareComponents)

Initializes a new instance of the class with the specified hardware components.

public HardwareId(HardwareComponents components)

Parameters

NameDescription

The hardware components used to generate the machine key.

Examples

HardwareId hardwareId = new HardwareId(HardwareComponents.Disk | HardwareComponents.Ethernet);
string hardwareKey = hardwareId.ToMachineKey();

HardwareId(HardwareComponents, byte[])

Initializes a new instance of the class with the specified hardware components and salt byte array to seed the key.

public HardwareId(HardwareComponents components, byte[] salt)

Parameters

NameDescription

The hardware components used to generate the machine key.

salt byte[]

A value used to seed the generated key.

Examples

This example shows how to create an hardware key with two bytes random salt.

Random rnd = new Random();

byte[] salt = new byte[2];
rnd.NextBytes(salt);

HardwareId hardwareId = new HardwareId(HardwareComponents.SystemName, salt);
string hardwareKey = hardwareId.ToMachineKey();

// Generates
// 1JIDI-CX9KK-93F8E-XQRWQ-G5DZ3-CGKX

Properties

RequiredComponents

Gets or sets the hardware components required to generate the hardware key identifier.

public HardwareComponents RequiredComponents { get; set; }

Property Value

HardwareComponents

Salt

Gets or sets the seed used to generate the key.

public byte[] Salt { get; set; }

Property Value

byte[]

Methods

Create()

Creates a hardware key using the best available hardware components.

public static HardwareId Create()

Returns

NameDescription

The HardwareId object with avaialble hardware components.

Remarks

Using the system name as the basis for generating a hardware key for license validation can be risky. The system name is typically a user-configurable setting and can be easily changed by the user, potentially leading to unauthorized access or abuse of the license system. Additionally, system names are not guaranteed to be unique, and different systems may have the same name, resulting in conflicts and inaccuracies in license validation. On the other hand, using hardware information such as Ethernet card MAC addresses can provide a more robust and unique basis for generating a hardware key.MAC addresses are assigned to network interface cards by the manufacturer and are globally unique, meaning that the likelihood of conflicts or inaccuracies is significantly reduced compared to using system names. However, it's important to note that MAC addresses can also be spoofed or manipulated in some cases. In general, it is recommended to use multiple hardware information points to create a hardware key for license validation, rather than relying solely on a single parameter like system name or MAC address. This can help increase the accuracy and security of license validation, and reduce the risks associated with potential conflicts or unauthorized access.

IsValid(string)

Query if 'key' is valid.

public static bool IsValid(string key)

Parameters

NameDescription

key string

The key.

Returns

NameDescription

true if valid, false if not.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

ToMachineKey(int)

Converts this object to a machine key.

public string ToMachineKey(int tokenSize = 5)

Parameters

NameDescription

tokenSize int

(Optional) Size of the readable token.

Returns

NameDescription

A string that represents the hardware components.

Exceptions

NameDescription

Thrown when one or more arguments have unsupported or illegal values.

Last updated