Class CdKey
Provides utilities for decoding and otherwise validating CD keys of Blizzard products. This class cannot be inherited.
Inheritance
Inherited Members
Namespace: MBNCSUtil
Assembly: MBNCSUtil.dll
Syntax
public sealed class CdKey
Constructors
| Improve this Doc View SourceCdKey(String)
Creates a CD key decoder for the specified key.
Declaration
public CdKey(string cdKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | cdKey | The CD key to initialize processing for. |
Remarks
This constructor only conducts initial validity checks to ensure that the CD key is valid; that is, it checks for a valid key length (13, 16, or 26 characters) and checks that the characters are valid for the key type. For example, Starcraft keys are numeric only, whereas Warcraft II, Diablo II, Lord of Destruction, Warcraft III, and The Frozen Throne keys are alphanumeric.
Additional validity checks are conducted internally; however, these do not raise Exceptions. To confirm the validity of a key after instantiation, call the CdKey.IsValid property.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the value of cdKey is null (Nothing in Visual Basic). |
System.ArgumentOutOfRangeException | Thrown if the CD key is an invalid length or does not pass initial validity checks. |
Properties
| Improve this Doc View SourceIsValid
Gets whether or not the CD key is valid.
Declaration
public bool IsValid { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
This property does not return whether or not this CD key is valid for Battle.net, but rather whether the product's installer would accept the key as valid.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
Key
Gets the CD key this object is processing.
Declaration
public string Key { get; }
Property Value
Type | Description |
---|---|
System.String |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
Product
Gets the product value encoded in the CD key.
Declaration
public int Product { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This property returns 0 if the CD key is not valid. To check validity, use the IsValid property.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
Value1
Gets the "Public" or "Value 1" value of the CD key.
Declaration
public int Value1 { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This property returns 0 if the CD key is not valid. To check validity, use the IsValid property.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
Value2
Gets the "Private" or "Value 2" value of the CD key.
Declaration
[Obsolete("This property will be removed in a future version. Consider changing to GetValue2().")]
public byte[] Value2 { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
Remarks
This property returns null (Nothing in Visual Basic) if the CD key is not valid. To check validity, use the IsValid property.
For Starcraft, Warcraft II: Battle.net Edition, Diablo II, or Lord of Destruction CD keys, this value is a 4-byte array. It can be converted to an integer value with the System.BitConverter class.
For Warcraft III: The Reign of Chaos and The Frozen Throne CD keys, this value is a 10-byte array.
Methods
| Improve this Doc View SourceCreateDecoder(String)
Creates a CD key decoder for the specified key.
Declaration
public static CdKey CreateDecoder(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The CD key to initialize processing for. |
Returns
Type | Description |
---|---|
CdKey | An instance of the CdKey class |
Remarks
This method only conducts initial validity checks to ensure that the CD key is valid; that is, it checks for a valid key length (13, 16, or 26 characters) and checks that the characters are valid for the key type. For example, Starcraft keys are numeric only, whereas Warcraft II, Diablo II, Lord of Destruction, Warcraft III, and The Frozen Throne keys are alphanumeric.
Additional validity checks are conducted internally; however, these do not raise Exceptions. To confirm the validity of a key after instantiation, call the CdKey.IsValid property.
This method is only a wrapper for the CdKey constructor and provides no additional functionality.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the value of key is null (Nothing in Visual Basic). |
System.ArgumentOutOfRangeException | Thrown if the CD key is an invalid length or does not pass initial validity checks. |
GetHash(Int32, Int32)
Computes the 20-byte hash value of the CD key.
Declaration
public byte[] GetHash(int clientToken, int serverToken)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | clientToken | A randomly-generated token value that is determined by session at the client. |
System.Int32 | serverToken | A randomly-generated token value that is determined by session at the server. |
Returns
Type | Description |
---|---|
System.Byte[] | A 20-byte array containing the hash value of the specified key. |
Remarks
The result of the hash calculation is used in the message 0x51 SID_AUTH_CHECK (from the client) as well as 0x36 SID_CDKEY2.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
GetHash(Int32, Int32, Boolean)
Computes the 20-byte hash value of the CD key.
Declaration
public byte[] GetHash(int clientToken, int serverToken, bool ignore)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | clientToken | A randomly-generated token value that is determined by session at the client. |
System.Int32 | serverToken | A randomly-generated token value that is determined by session at the server. |
System.Boolean | ignore |
Returns
Type | Description |
---|---|
System.Byte[] | A 20-byte array containing the hash value of the specified key. |
Remarks
The result of the hash calculation is used in the message 0x51 SID_AUTH_CHECK (from the client) as well as 0x36 SID_CDKEY2.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
GetHash(UInt32, UInt32)
Computes the 20-byte hash value of the CD key. This method is not CLS-compliant.
Declaration
[CLSCompliant(false)]
public byte[] GetHash(uint clientToken, uint serverToken)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | clientToken | A randomly-generated token value that is determined by session at the client. |
System.UInt32 | serverToken | A randomly-generated token value that is determined by session at the server. |
Returns
Type | Description |
---|---|
System.Byte[] | A 20-byte array containing the hash value of the specified key. |
Remarks
The result of the hash calculation is used in the message 0x51 SID_AUTH_CHECK (from the client) as well as 0x36 SID_CDKEY2.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
GetHash(UInt32, UInt32, Boolean)
Computes the 20-byte hash value of the CD key. This method is not CLS-compliant.
Declaration
[CLSCompliant(false)]
public byte[] GetHash(uint clientToken, uint serverToken, bool ignore)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | clientToken | A randomly-generated token value that is determined by session at the client. |
System.UInt32 | serverToken | A randomly-generated token value that is determined by session at the server. |
System.Boolean | ignore |
Returns
Type | Description |
---|---|
System.Byte[] | A 20-byte array containing the hash value of the specified key. |
Remarks
The result of the hash calculation is used in the message 0x51 SID_AUTH_CHECK (from the client) as well as 0x36 SID_CDKEY2.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the object has not yet been initialized. |
GetValue2()
Gets the "Private" or "Value 2" value of the CD key.
Declaration
public byte[] GetValue2()
Returns
Type | Description |
---|---|
System.Byte[] |
Remarks
This method returns null (Nothing in Visual Basic) if the CD key is not valid. To check validity, use the IsValid property.
For Starcraft, Warcraft II: Battle.net Edition, Diablo II, or Lord of Destruction CD keys, this value is a 4-byte array. It can be converted to an integer value with the System.BitConverter class.
For Warcraft III: The Reign of Chaos and The Frozen Throne CD keys, this value is a 10-byte array.