UniKey API Reference for Delphi Language: Difference between revisions
| (12 intermediate revisions by the same user not shown) | |||
| Line 702: | Line 702: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__Write_SoftID(pHandle: pWord; | <code>function UniKey__Write_SoftID(pHandle: pWord; pSoftID: pLongWord): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
| Line 720: | Line 720: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pSoftID</td> | ||
<td>[in] Software ID</td> | <td>[in] Software ID</td> | ||
</tr> | </tr> | ||
| Line 1,155: | Line 1,155: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterA</td> | ||
<td>[in, out] Register A</td> | <td>[in, out] Register A</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterB</td> | ||
<td>[in, out] Register B</td> | <td>[in, out] Register B</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterC</td> | ||
<td>[in, out] Register C</td> | <td>[in, out] Register C</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterD</td> | ||
<td>[in, out] Register D</td> | <td>[in, out] Register D</td> | ||
</tr> | </tr> | ||
| Line 1,291: | Line 1,291: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterA</td> | ||
<td>[in, out] Register A</td> | <td>[in, out] Register A</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterB</td> | ||
<td>[in, out] Register B</td> | <td>[in, out] Register B</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterC</td> | ||
<td>[in, out] Register C</td> | <td>[in, out] Register C</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterD</td> | ||
<td>[in, out] Register D</td> | <td>[in, out] Register D</td> | ||
</tr> | </tr> | ||
| Line 1,419: | Line 1,419: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterA</td> | ||
<td>[in, out] Register A</td> | <td>[in, out] Register A</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterB</td> | ||
<td>[in, out] Register B</td> | <td>[in, out] Register B</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterC</td> | ||
<td>[in, out] Register C</td> | <td>[in, out] Register C</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pRegisterD</td> | ||
<td>[in, out] Register D</td> | <td>[in, out] Register D</td> | ||
</tr> | </tr> | ||
| Line 1,692: | Line 1,692: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__Generate_Key(pHandle: pWord; | <code>function UniKey__Generate_Key(pHandle: pWord; pKeyNumber: pLongWord): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
| Line 1,985: | Line 1,985: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__MD5(pHandle: pWord; | <code>function UniKey__MD5(pHandle: pWord; pBufferLength: pLongWord; pBuffer: pByteArray): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
| Line 2,610: | Line 2,610: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pModule</td> | ||
<td>[in] Real-time module number (0-15)</td> | <td>[in] Real-time module number (0-15)</td> | ||
</tr> | </tr> | ||
| Line 2,669: | Line 2,669: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> | <td>pModule</td> | ||
<td>[in] Real-time module number (0-15)</td> | <td>[in] Real-time module number (0-15)</td> | ||
</tr> | </tr> | ||
| Line 2,788: | Line 2,788: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__Check_Time_Module(pHandle: pWord; pModule: pLongWord; | <code>function UniKey__Check_Time_Module(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pYear: pWord; pMonth: pWord; pDay: pWord; pHour: pWord): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
| Line 2,874: | Line 2,874: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__Check_Time_Module_Now(pHandle: pWord; pModule: pLongWord; | <code>function UniKey__Check_Time_Module_Now(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pRemainHours: pWord): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
| Line 2,948: | Line 2,948: | ||
'''API Prototype''' | '''API Prototype''' | ||
<code>function UniKey__Check_Time_Module_Now_PC(pHandle: pWord; pModule: pLongWord; | <code>function UniKey__Check_Time_Module_Now_PC(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pRemainHours: pWord): DWORD; stdcall;</code> | ||
'''Description''' | '''Description''' | ||
Latest revision as of 17:18, 13 July 2016
UniKey API Reference
Find a UniKey dongle
API Prototype
function UniKey__Find(pHandle: pWord; pSetting1: pLongWord; pSetting2: pLongWord): DWORD; stdcall;
Description
Check if a specific UniKey is attached to the USB port. This is the first API used to start a UniKey session.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [out] Dongle handle |
| pSetting1 | [in] Working mode (UniKey PRO only), useless for UniKey STD |
| [out] Hardware ID | |
| pSetting2 | [in] Access mode (UniKey PRO only), useless for UniKey STD |
| [out] Number of dongles attached, useless for UniKey STD |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NOT_FOUND | 200 | No UniKey dongle |
For UniKey PRO (Network UniKey), *pSetting specifies the working mode. If you do not specify the value in *lp1, the working mode will be read from the NetUniKey.ini.
Find the Next UniKey dongle
API Prototype
function UniKey__Find_Next(pHandle: pWord; pSetting1: pLongWord; pSetting2: pLongWord): DWORD; stdcall;
Description
Check if another UniKey is attached to the USB port.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [out] Dongle handle |
| pSetting1 | [in] Working Mode (UniKey PRO only), useless for UniKey STD |
| [out] Hardware ID | |
| pSetting2 | [in] Access Mode (UniKey PRO only), useless for UniKey STD |
| [out] Number of dongles attached , useless for UniKey STD |
Return values
| Result | Value | Meaning |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NOMORE | 214 | No more dongles found |
| ERROR_UNIKEY_NEED_FIND | 215 | Find needs to be called before Find_Next |
Log on to UniKey Dongle
API Prototype
function UniKey__User_Logon(pHandle: pWord; pPassword1: pWord; pPassword2: pWord): DWORD; stdcall;
For UniKey Drive, the API Prototype is
function UniKey__User_Logon(pHandle: pWord; pPassword1: pWord; pPassword2: pWord): DWORD; stdcall;
Description
Log in to a UniKey dongle with specified passwords. This API should be called in the commercial software in order to improve security.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [out] Dongle handle |
| pPassword1 | [in] Password 1 |
| pPassword2 | [in] Password 2 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NOT_FOUND | 200 | No UniKey dongle |
| ERROR_UNIKEY_INVALID_PASSWORD | 201 | Found UniKey dongle, but basic passwords (password 1 and 2) are incorrect |
| ERROR_UNIKEY_INVALID_PASSWORD_OR_ID | 202 | Wrong password or UniKey HID |
Log on to UniKey Dongle in vendor mode
API Prototype
function UniKey__Vender_Logon(pHandle: pWord; pPassword1: pWord; pPassword2: pWord; pPassword3: pWord; pPassword4: pWord): DWORD; stdcall;
For UniKey Drive, the API Prototype is
function UniKey__Vender_Logon(pHandle: pWord; pPassword1: pWord; pPassword2: pWord; pPassword3: pWord; pPassword4: pWord): DWORD; stdcall;
Description
Log in to a UniKey dongle in vendor mode with specified passwords. This API helps software vendors to log in to the UniKey dongle in vendor mode, and get full permissions to the UniKey dongle.
We do NOT advise you to enclose this API in the final released software. This API is only for software vendor’s usage.
If password 3 or 4 is wrong, while password 1 and 2 is correct, the dongle is then logged on in user mode automatically.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [out] Dongle handle |
| pPassword1 | [in] Password 1 |
| pPassword2 | [in] Password 2 |
| pPassword3 | [in] Password 3 |
| pPassword4 | [in] Password 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NOT_FOUND | 200 | No UniKey dongle |
| ERROR_UNIKEY_INVALID_PASSWORD | 201 | Found UniKey dongle, but basic passwords (password 1 and 2) are incorrect |
| ERROR_UNIKEY_INVALID_PASSWORD_OR_ID | 202 | Wrong password or UniKey HID |
Log off the UniKey dongle
API Prototype
function UniKey__Logoff(pHandle: pWord): DWORD; stdcall;
Description
Log off a UniKey dongle with a specific handle; this API should be called at the end of a UniKey session.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NOT_FOUND | 200 | No UniKey dongle |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
Get the UniKey Dongle's Type
API Prototype
function UniKey__Get_Type(pHandle: pWord; type: pLongWord): DWORD; stdcall;
Description
UniKey__Get_Type can help you get the type of the UniKey dongle.
This functions return value will help to indicate the type of the UniKey dongle.
| Type | Code |
|---|---|
| UNIKEY_TYPE_TIME | 101 |
| UNIKEY_TYPE_PRO | 102 |
| UNIKEY_TYPE_STD | 103 |
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| type | [out] The value indicating the type of your UniKey dongle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_GET_TYPE | 256 | UniKey Get Type Error |
Read UniKey dongle memory
API Prototype
function UniKey__Read_Memory(pHandle: pWord; pStartAddress: pWord; pBufferLength: pWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Read the contents of memory; this API needs to be called after logging in to a UniKey dongle.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Offset of Memory |
| pBufferLength | [in] Number of bytes to read |
| pBuffer | [out] Pointer to the buffer containing the data to be read |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_READ_MEMORY | 207 | Read Error |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
Write to UniKey dongle memory
API Prototype
function UniKey__Write_Memory(pHandle: pWord; pStartAddress: pWord; pBufferLength: pWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Write data into memory; this API needs to be called after logging on to a UniKey dongle.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Offset of the memory |
| pBufferLength | [in] Number of bytes to write |
| pBuffer | [in] Pointer to the buffer containing the data to be written |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_WRITE_MEMORY | 207 | Write Error |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_VERIFY_ADV_PASSWORD | 223 | Advanced passwords (password 3 and 4) not verified |
To write the last 2k memory (for 2048 – 4096), you need to verify all 4 passwords (vendor mode) to obtain the requisite permission.
UniKey__Read_Memory and UniKey__Write_Memory provide basic reading and writing functions to the dongle. You can store general information via such functions. And various levels of security can be applied too.
Generate a Random Number
API Prototype
function UniKey__Random(pHandle: pWord; pReturn1: pWord; pReturn2: pWord; pReturn3: pWord; pReturn4: pWord): DWORD; stdcall;
Description
Generates random numbers from the dongle.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pReturn1 | [out] Random number |
| pReturn2 | [out] Random number |
| pReturn3 | [out] Random number |
| pReturn4 | [out] Random number |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_RANDOM | 209 | Random number error |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
UniKey__Random is used to generate a random number inside the dongle. The UniKey dongle computation engine generates the number and the hardware of the dongle is the seed for the random number.
Generate Seed Code Return Values
API Prototype
function UniKey__Seed(pHandle: pWord; pSeed: pLongWord; pReturn1: pWord; pReturn2: pWord; pReturn3: pWord; pReturn4: pWord): DWORD; stdcall;
Description
Get return codes from the input of a seed code; this API return for values which are related to pSeed and the UniKey dongle’s password.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pSeed | [in] Seed code |
| pReturn1 | [out] Return code 1 |
| pReturn2 | [out] Return code 2 |
| pReturn3 | [out] Return code 3 |
| pReturn4 | [out] Return code 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_SEED | 210 | Seed code error |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
UniKey__Seed generate a set of seed codes; all of these seed codes are based on the password. providing another method to verify passwords and check if a dongle has been inserted. Apart from this, the seed codes can be used in other computations, for example, you can use the seed returned as a 64-bit encryption key.
Write Software ID
API Prototype
function UniKey__Write_SoftID(pHandle: pWord; pSoftID: pLongWord): DWORD; stdcall;
Description
Write the vendor-defined software ID.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pSoftID | [in] Software ID |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_SET_SOFTID | 203 | Set software ID error |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
You need to verify all 4 passwords (vendor mode) to write the software ID to the dongle.
Read Software ID
API Prototype
function UniKey__Read_SoftID(pHandle: pWord; pSoftID: pLongWord): DWORD; stdcall;
Description
Read the user-defined software ID.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pSoftID | [out] Software ID |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
UniKey__Write_SoftID and UniKey__Read_SoftID provide a means to make a soft (write-able) ID for each software. You can write different software ID for each software and call UNIKEY_READ_SOFTID to check if the software ID is correct.
Set a UniKey License module
API Prototype
function UniKey__Set_Module(pHandle: pWord; pModule: pWord; pValue: pWord; pDecrease: pWord): DWORD; stdcall;
Description
To write a value to a specific UniKey license module and set the Decrement attribute.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module number |
| pValue | [in] License module unit value |
| pDecrease | [in] Decrement attribute (1 = allowed, 0 = not allowed) |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 202 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
A successful operation will result in license module unit number *pModule storing value *pValue, and the Decrement attribute set to "0" or "1".
You need to verify all 4 passwords (vendor mode) to set a module value successfully.
Get a UniKey License module
API Prototype
function UniKey__Get_Module(pHandle: pWord; pModule: pWord; pValue: pWord): DWORD; stdcall;
Description
Get a value from a specific UniKey license module.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Module Number |
| pValue | [out] Return the value in module |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 202 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
You need to verify 2 passwords (user mode) to get a module value successfully.
Check a UniKey License module
API Prototype
function UniKey__Check_Module(pHandle: pWord; pModule: pWord; pValues: pWord; pDecrease: pWord): DWORD; stdcalll;
Description
Read the attributes of a specific UniKey license module.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module number |
| pValue | [out] Validity (1 = license module value is not zero) |
| pDecrease | [out] Decrement attribute (1 = license module can be decreased) |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 202 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
A successful operation will result in *pValue having value from Validity (1 = license module value is not zero), and *pDecrease having value from the Decrement attribute (1 = license module can be decreased). The value of a license module cannot be read directly, and it is invisible to end users.
UniKey__Set_Module and UniKey__Check_Module provide an easy way to implement software limitations. For example, if you want to set software to only be executed 3 times, you can call UniKey__Set_Module to set a license module (let us say license module 0) as 3. And, during each execution, we decrease the license module, if the license module is invalid (zero), we stop the software. Apart from this, we can implement a module-selling model with the help of license module functions. For example, the software has four function modules, A, B, C and D. And we can map the function modules to the license modules in the UniKey dongle. Let us say that function module A is mapped to license module 0, B to 1, C to 2 and D to 3. If a customer only buys function A and B, you only need to enable license module 0 and 1, and leave 2 and 3 as zero. So now only function module A and B can be executed. If the customer buys additional functions, you can use the UniKey Remote Updater tool to update the dongle as needed remotely.
Write Arithmetic
API Prototype
function UniKey__Write_Arithmetic(pHandle: pWord; pStartAddress: pWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Write user-defined mathematical algorithms.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Offset of first instruction |
| pBuffer | [in] Pointer to the algorithm command string |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_AR_BAD_COMMAND | 217 | Arithmetic instruction error |
| ERROR_UNIKEY_AR_UNKNOWN_OPCODE | 218 | Arithmetic operator error |
| ERROR_UNIKEY_AR_WRONG_BEGIN | 219 | Constant numbers can't be used on first arithmetic instruction |
| ERROR_UNIKEY_AR_WRONG_END | 220 | Constant numbers can't be used on last arithmetic instruction |
| ERROR_UNIKEY_AR_VALUE_OVERFLOW | 221 | Constant numbers > 63 will cause an overflow |
A successful operation will result in a user-defined algorithm containing the algorithm command string from the buffer.
UniKey__Write_Arithmetic is called when you write a series of algorithms into the dongle. This function is only called on the software vendor side. For example, if you have a serial number generator algorithm, and you want to perform this algorithm inside the dongle, you need to call UniKey__Write_Arithmetic
User-Defined Algorithm Calculate 1
API Prototype
function UniKey__Calculate1(pHandle: pWord; pStartAddress: pLongWord; pModule: pLongWord; pRegisterA: pWord; pRegisterB: pWord; pRegisterC: pWord; pRegisterD: pWord): DWORD; stdcall;
Description
Return the results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE1 function.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Start point of calculation |
| pModule | [in] License module number |
| pRegisterA | [in, out] Register A |
| pRegisterB | [in, out] Register B |
| pRegisterC | [in, out] Register C |
| pRegisterD | [in, out] Register D |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_AR_BAD_COMMAND | 217 | Arithmetic instruction error |
| ERROR_UNIKEY_AR_UNKNOWN_OPCODE | 218 | Arithmetic operator error |
| ERROR_UNIKEY_AR_WRONG_BEGIN | 219 | Constant numbers can't be used on first arithmetic instruction |
| ERROR_UNIKEY_AR_WRONG_END | 220 | Constant numbers can't be used on last arithmetic instruction |
| ERROR_UNIKEY_AR_VALUE_OVERFLOW | 221 | Constant numbers > 63 will cause an overflow |
When the calculation starts, the values of other internal registers are listed in the table below.
E and F is the bytewise reversed hardware ID. For example, if the hardware is 0x12345678 (in hex), then E will be 0x7856 and F will be 0x3412.
| Internal Register | Description |
|---|---|
| E | High-order byte of reversed hardware ID |
| F | Low-order byte of reversed hardware ID |
| G | Value stored in license module *pModule |
| H | Random number |
Examples:
If the internal algorithm is A = B + C, then the call result is *pRegA = *pRegB + *pRegC
The internal algorithm is A = A + G; if *pRegA = 0, then you may guess the result is the license module such that *pRegA = G = *pModule
Though you cannot read the content of modules directly, you can determine the content by an algorithm. If possible, it would be best to also check this content with an algorithm, and not only compare it in the program.
User-Defined Algorithm Calculate 2
API Prototype
function UniKey__Calculate2(pHandle: pWord; pStartAddress: pLongWord; pSeed: pLongWord; pRegisterA: pWord; pRegisterB: pWord; pRegisterC: pWord; pRegisterD: pWord): DWORD; stdcall;
Description
Return the results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE2 function.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Start point of calculation |
| pSeed | [in] Seed code (32-bit) |
| pRegisterA | [in, out] Register A |
| pRegisterB | [in, out] Register B |
| pRegisterC | [in, out] Register C |
| pRegisterD | [in, out] Register D |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_AR_BAD_COMMAND | 217 | Arithmetic instruction error |
| ERROR_UNIKEY_AR_UNKNOWN_OPCODE | 218 | Arithmetic operator error |
| ERROR_UNIKEY_AR_WRON_GBEGIN | 219 | Constant numbers can't be used on first arithmetic instruction |
| ERROR_UNIKEY_AR_WRONG_END | 220 | Constant numbers can't be used on last arithmetic instruction |
| ERROR_UNIKEY_AR_VALUE_OVERFLOW | 221 | Constant numbers > 63 will cause an overflow |
When using calculate 2, the initial values of register E, F, G and H are the return values of seed code *pSeed, to make it simple, the UniKey calls function SEED with seed code *pSeed, and writes the return values to register E, F, G and H for the next operation.
| Internal Register | Description |
|---|---|
| E | Seed result 1 |
| F | Seed result 2 |
| G | Seed result 3 |
| H | Seed result 4 |
User-Defined Algorithm Calculate 3
API Prototype
function UniKey__Calculate3(pHandle: pWord; pStartAddress: pLongWord; pModule: pLongWord; pRegisterA: pWord; pRegisterB: pWord; pRegisterC: pWord; pRegisterD: pWord): DWORD; stdcall;
Description
Return results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE3 function.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pStartAddress | [in] Start point of calculation |
| pModule | [in] License module number |
| pRegisterA | [in, out] Register A |
| pRegisterB | [in, out] Register B |
| pRegisterC | [in, out] Register C |
| pRegisterD | [in, out] Register D |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_AR_BAD_COMMAND | 217 | Arithmetic instruction error |
| ERROR_UNIKEY_AR_UNKNOWN_OPCODE | 218 | Arithmetic operator error |
| ERROR_UNIKEY_AR_WRON_GBEGIN | 219 | Constant numbers can't be used on first arithmetic instruction |
| ERROR_UNIKEY_AR_WRONG_END | 220 | Constant numbers can't be used on last arithmetic instruction |
| ERROR_UNIKEY_AR_VALUE_OVERFLOW | 221 | Constant numbers > 63 will cause an overflow |
When using calculate 3, the initial values of register E, F, G and H are the content of license module *lp2 and *lp2 + 1/2/3.
| Internal Register | Description |
|---|---|
| E | Value in license module *lp2 |
| F | Value in license module (*lp2 + 1) |
| G | Value in license module (*lp2 + 2) |
| H | Value in license module (*lp2 + 3) |
Examples:
When calling calculation 3 with *pModule = 0, the initial values of register E, F, G and H are:
E = value of license module 0
F = value of license module 1
G = value of license module 2
F = value of license module 3
Note: The address will return to "0" when the license module address call exceeds 128. For example: Calculation 3 with *pModule = 126, the initial values of register E, F, G and H are:
E = value of license module 126
F = value of license module 127
G = value of license module 0
H = value of license module 1
UniKey__Calculate is called when you want to perform the algorithm you have written inside the UniKey dongle. For example, you have written a formula into the dongle, you can call UniKey__Calculate to perform the algorithm and get the return value of the formula.
Decrease a License Module
API Prototype
function UniKey__Module_Decrease(pHandle: pWord; pModule: pWord): DWORD; stdcall;
Description
Decrease the value in a specified UniKey license module by "1".
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module number |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
Please call UniKey__Check_Module to check if the license module is valid first.
Generate a New Password
API Prototype
function UniKey__Generate_New_Password(pHandle: pWord; pSeed: pLongWord; pPassword1: pWord; pPassword2: pWord; pPassword3: pWord; pPassword4: pWord): DWORD; stdcall;
Description
Generate a new password via a seed code; the mapping from the seed code to the password is a one-way function. Without the seed, you cannot generate the same password.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pSeed | [in] Seed code (32-bit) |
| pPassword1 | [out] New password 1 |
| pPassword2 | [out] New password 2 |
| pPassword3 | [out] New password 3 |
| pPassword4 | [out] New password 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_VERIFY_ADV_PASSWORD | 223 | Advanced passwords (passwords 3 and 4) not verified |
| ERROR_UNIKEY_GENERATE_NEW_PASSWORD | 225 | Error generating new password |
A file recording the new seed and passwords will be created in the working path, helping the software vendor to record everything. The passwords can be distributed to ordinary developers!
- The dongle will automatically log off after a new set of passwords have been generated.
- The dongle will be fully formatted when a new password is generated.
- A file including the new passwords and seed will be created in the working directory.
Generate a New Encryption Key
API Prototype
function UniKey__Generate_Key(pHandle: pWord; pKeyNumber: pLongWord): DWORD; stdcall;
Description
Generate a new key in the specific key storage.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pKeyNumber | [in] Key storage number |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_INVALID_KEY_STORE | 224 | Wrong key storage number |
- This function will delete the original key in the key storage, and generate a new key.
- The data encrypted by the old key cannot be decrypted by the new key.
- Each key is 128-bits long.
Generate a New Encryption Key via Seed
API Prototype
function UniKey__Generate_Key_Via_Seed (pHandle: pWord; pKeyNumber: pLongWord; pSeed1: pWord; pSeed2: pWord; pSeed3: pWord; pSeed4: pWord): DWORD; stdcall;
Description
Generate a new key in the specific key storage via a seed.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pKeyNumber | [in] Key storage number |
| pSeed1 | [in] Seed 1 |
| pSeed2 | [in] Seed 2 |
| pSeed3 | [in] Seed 3 |
| pSeed4 | [in] Seed 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_INVALID_KEY_STORE | 224 | Wrong key storage number |
- This function will delete the original key in the key storage, and generate a new key via seed.
- The data encrypted by the old key cannot be decrypted by the new key.
- Each key is 128-bit long.
Encrypt the Buffer with a Specific Encryption Key
API Prototype
function UniKey__Encrypt(pHandle: pWord; pBufferLength: pLongWord; pKeyNumber: pLongWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
Parameters
| Parameter | Meaning |
|---|---|
| pHandle | [in] Dongle handle |
| pBufferLength | [in] Number of bytes to encrypt |
| pKeyNumber | [in] Key storage number |
| pBuffer | [in] Pointer to the data to be encrypted |
| [out] Pointer to the encrypted data |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_INVALID_KEY_STORE | 224 | Wrong key storage number |
| ERROR_UNIKEY_ENCRYPT_FAILED | 228 | Could not encrypt data |
This function only performs an encryption operation, no compression functions are involved.
Decrypt the Buffer with a Specific Encryption Key
API Prototype
function UniKey__Decrypt(pHandle: pWord; pBufferLength: pLongWord; pKeyNumber: pLongWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
Parameters
| Parameter | Meaning |
|---|---|
| pHandle | [in] Dongle handle |
| pBufferLength | [in] Number of bytes to encrypt |
| pKeyNumber | [in] Key storage number |
| pBuffer | [in] Pointer to the data to be decrypted |
| [out] Pointer to the decrypted data |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_INVALID_KEY_STORE | 224 | Wrong key storage number |
| ERROR_UNIKEY_DECRYPT_FAILED | 229 | Could not decrypt data |
Please use the key that was used to encrypt the data to decrypt the data, otherwise you cannot properly decrypt the data.
UniKey__Encrypt and UniKey__Decrypt offer a basic 128-bit encryption/decryption operation based on UniKey’s hardware. You can call these functions when an encryption or decryption operation is needed. For better security, you can encrypt a credential before saving it into the UniKey’s memory.
Make an MD5 Digest for Certain Content
API Prototype
function UniKey__MD5(pHandle: pWord; pBufferLength: pLongWord; pBuffer: pByteArray): DWORD; stdcall;
Description
Make an MD5 digest of content or data.
Parameters
| Parameter | Meaning |
|---|---|
| pHandle | [in] Dongle handle |
| pBufferLength | [in] Number of bytes to MD5 |
| pBuffer | [in] Pointer to the data to be digested |
| [out] Pointer to the digested data |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
Read UpdateTag
API Prototype
function UniKey__Read_UpdateTag(pHandle: pWord; pUpdateTag: pLongWord): DWORD; stdcall;
Description
Read UpdateTag from a specific dongle
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pUpdateTag | [out] UpdateTag |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_READ_UPDATETAG | 226 | Read UpdateTag error |
Write UpdateTag
API Prototype
function UniKey__Write_UpdateTag(pHandle: pWord; pUpdateTag: pLongWord): DWORD; stdcall;
Description
Write UpdateTag into a specific dongle.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pUpdateTag | [in] UpdateTag |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_UPDATETAG | 227 | Write UpdateTag error |
UniKey__Read_UpdateTag APIs give software vendors an easy method to identify if the UniKey dongle needs to be updated. When distributing software, software vendors may use the UpdateTag as an ID which shows if the dongle needs to be updated or has been updated. You can also use this tag as a tracking ID for each update.
Get UniKey Library Version
API Prototype
function UniKey__Get_Version(pHandle: pWord; pVersion: pLongWord): DWORD; stdcall;
Description
Get the current UniKey library version.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pVersion | [out] UniKey library version |
UniKey Time API Reference
Get UniKey Time
API Prototype
function UniKey__Get_Time(pHandle: pWord; pYear: pLongWord; pMonth: pLongWord; pDay: pWord; pHour: pWord; pMinute: pWord; pSecond: pWord): DWORD; stdcall;
Description
Get the time from the UniKey Time’s real-time clock.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pYear | [out] Year (input or output is 10, which refers to 2010) |
| pMonth | [out] Month |
| pDay | [out] Day |
| pHour | [out] Hour |
| pMinute | [out] Minute |
| pSecond | [out] Second |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_READ_TIME | 230 | Get UniKey time error |
Calling UniKey__Check_Time can check if the dongle is a UniKey Time model. If ERROR_UNIKEY_READ_TIME is returned, then the dongle is not a UniKey Time.
Set UniKey Time
API Prototype
function UniKey__Set_Time(pHandle: pWord; pYear: pLongWord; pMonth: pLongWord; pDay: pWord; pHour: pWord; pMinute: pWord; pSecond: pWord): DWORD; stdcall;
Description
Set the time on the UniKey Time’s clock.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pYear | [in] Year (input or output is 10, which refers to 2010) |
| pMonth | [in] Month |
| pDay | [in] Day |
| pHour | [in] Hour |
| pMinute | [in] Minute |
| pSecond | [in] Second |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_READ_TIME | 230 | Get UniKey time error |
You need to verify all 4 passwords (vendor mode) to set the time of the UniKey Time's internal clock.
Set UniKey Time by Host’s Clock
API Prototype
function UniKey__Set_Time_Now(pHandle: pWord): DWORD; stdcall;
Description
Set the time of the UniKey Time’s real-time clock to the host computer’s clock.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME | 231 | Set UniKey time error |
Erase Real Time Module
API Prototype
function UniKey__Erase_Time_Module(pHandle: pWord; pModule: pLongWord): DWORD; stdcall;
Description
Erase/Reset a real-time module, and all the information in the module will be erased including start, and end or duration.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME | 231 | Set UniKey time error |
You need to verify all 4 passwords (vendor mode) to reset a module. If a real-time module’s write-once flag is enabled, only the first START_TIME call works. Successive START_TIME calls will return an error until this module is reset.
Set a Real Time Module’s Start Time
API Prototype
function UniKey__Set_Time_Module_Start_Time(pHandle: pWord; pModule: pLongWord; pYear: pWord; pMonth: pWord; pDay: pWord; pHour: pWord): DWORD; stdcall;
Description
Set a real-time module’s start time.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
| pYear | [in] Year (input or output is 10, which refers to 2010) |
| pMonth | [in] Month |
| pDay | [in] Day |
| pHour | [in] Hour |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME_MODULE | 231 | Set UniKey time error |
| ERROR_UNIKEY_TIME_MODULE_NOT_NULL | 234 | The real-time module is not null, this error is returned when the 'write once' flag is set |
The write-once flag is very useful for setting the start for a real-time module. If the write-once flag is set, only the first START_TIME call can set the start time for a module; all successive START_TIME calls will not work and return an ERROR_UNIKEY_TIME_MODULE_NOT_NULL. Software vendors may use this flag when the start for a module is not clear.
Set a Real Time Module’s Start Time by the UniKey's Internal Clock
API Prototype
function UniKey__Set_Time_Module_Start_Time_Now(pHandle: pWord; pModule: pLongWord): DWORD; stdcall;
Description
Set a real-time module’s start time as the current time in the UniKey's internal clock.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME_MODULE | 231 | Set UniKey time error |
| ERROR_UNIKEY_TIME_MODULE_NOT_NULL | 234 | The real-time module is not null, this error is returned when the 'write once' flag is set |
Set a Real Time Module’s Start Time by Host’s Clock
API Prototype
function UniKey__Set_Time_Module_Start_Time_Now_PC(pHandle: pWord; pModule: pLongWord): DWORD; stdcall;
Description
Set a real time module’s start time as the current time of the host computer.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME_MODULE | 231 | Set UniKey time error |
| ERROR_UNIKEY_TIME_MODULE_NOT_NULL | 234 | The real-time module is not null, this error is returned when the 'write once' flag is set |
Set a Real Time Module’s End Time
API Prototype
function UniKey__Set_Time_Module_End_Time(pHandle: pWord; pModule: pLongWord; pYear: pWord; pMonth: pWord; pDay: pWord; pHour: pWord): DWORD; stdcall;
Description
Set a real-time module’s end time.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
| pYear | [in] Year (input or output is 10, which refers to 2010) |
| pMonth | [in] Month |
| pDay | [in] Day |
| pHour | [in] Hour |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME_MODULE | 231 | Set UniKey time error |
Set a Real Time Module’s Duration
API Prototype
function UniKey__Set_Time_Module_Duration(pHandle: pWord; pModule: pLongWord; pDay: pLongWord; pHour: pWord): DWORD; stdcall;
Description
Set the duration for a specific real-time module. The total duration is (*pDay) * 24 + (*pHour) in hours.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] Real-time module number (0-15) |
| pDay | [in] Number of days |
| pHour | [in] Number of hours |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_WRITE_TIME_MODULE | 231 | Set UniKey time error |
You need to verify all 4 passwords (vendor mode) to set the duration for a real-time module.
Check a UniKey Time License module
API Prototype
function UniKey__Check_Time_Module(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pYear: pWord; pMonth: pWord; pDay: pWord; pHour: pWord): DWORD; stdcall;
Description
Read the attributes of a specific UniKey Time license module.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module Number |
| pRemainDays | [out] Days remaining |
| pYear | [in] Year (input or output is 10, which refers to 2010) |
| pMonth | [in] Month |
| pDay | [in] Day |
| pHour | [in] Hour |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
A successful operation will result in *pValue having value from the validity of a license module (1 = license module value is not zero).
The value of a license module cannot be read out directly and it is invisible to end users.
Check a UniKey Time License Module Now
API Prototype
function UniKey__Check_Time_Module_Now(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pRemainHours: pWord): DWORD; stdcall;
Description
Read the attributes of a specific UniKey Time license module Now.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module number |
| pRemainDays | [out] Days remaining |
| pRemainHours | [out] Hours remaining |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
A successful operation will result in *pValue having value from the validity (1 = license module value is not zero).
The value of a license module cannot be read out directly and it is invisible to end users.
Check a UniKey Time License Module Now PC
API Prototype
function UniKey__Check_Time_Module_Now_PC(pHandle: pWord; pModule: pLongWord; pRemainDays: pLongWord; pRemainHours: pWord): DWORD; stdcall;
Description
Read the attributes of a specific UniKey Time license module Now PC.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Dongle handle |
| pModule | [in] License module number |
| pRemainDays | [out] Days remaining |
| pRemainHours | [out] Hours remaining |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_ADDR_OR_SIZE | 204 | Read/Write address is incorrect or invalid length |
| ERROR_UNIKEY_NEED_OPEN | 212 | Need to log on to a dongle before running |
| ERROR_UNIKEY_MODULE | 216 | License module error |
A successful operation will result in *pValue having value from the validity (1 = license module value is not zero).
The value of a license module cannot be read out directly and it is invisible to end users.
UniKey Drive API Reference
Initialize File System
API Prototype
function UniKey_FS_Init(pHandle: pWord; PW1: pLongWord; PW2: pLongWord; PW3: pLongWord; PW4: pLongWord): DWORD; stdcall;
Description
The user needs to call this function to initialize the file system before calling other file system related functions. The default password of the file system is "12345678", without quotations.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| PW1 | [in] Password 1 |
| PW2 | [in] Password 2 |
| PW3 | [in] Password 3 |
| PW4 | [in] Password 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_PASSWORD_OR_ID | 202 | Wrong password or UniKey HID |
Format the File System
API Prototype
function UniKey_FS_Format(pHandle: pWord): DWORD; stdcall;
Description
Format the file system.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_FILE_EXIST | 245 | File already exists |
Note: The user needs to initialize the file system successfully before calling other file system related functions.
Create Files
API Prototype
function UniKey_FS_CreateFile(pHandle: pWord; filename: pByteArray): DWORD; stdcall;
Description
Create files.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filename | [in/out] Input/Output file name |
Note: a single backslash ("\") should be added before the name of the file.
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_FILE_NAME | 240 | Wrong or invalid filename |
| ERROR_UNIKEY_FS_FILE_EXIST | 245 | File already exists |
| ERROR_UNIKEY_FS_ERR_SYS_UNINIT | 246 | The file system is not initialized |
Delete Files
API Prototype
function UniKey_FS_DeleteFile(pHandle: pWord; filename: pByteArray): DWORD; stdcall;
Description
Delete files.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filename | [in/out] Input/Output file name |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_NO_FILE | 241 | No such filename |
| ERROR_UNIKEY_FS_ERR_SYS_UNINIT | 246 | The file system is not initialized |
Open Files
API Prototype
function UniKey_FS_File_Open(pHandle: pWord; filename: pChar): DWORD; stdcall;
Description
Open files.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filename | [in] Input/Output file name |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_NO_FILE | 241 | No such filename |
Get System Space
API Prototype
function UniKey_FS_Get_Free_Size(pHandle: pWord; usedsize: pLongWord; freesize: pLongWord): DWORD; stdcall;
Description
Get occupied and free system space.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| usedsize | [out] System memory that is in use |
| freesize | [out] Free system memory |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
Modify File Data
API Prototype
function UniKey_FS_File_Modify_Data(pHandle: pWord; offset: pLongWord; len: pLongWord; buffer: pByteArray): DWORD; stdcall;
Description
Modify file data.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| offset | [in] Address to be modified |
| len | [in] Length of data to be modified |
| buffer | [in] Modified data |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_FILE_OFFSET | 242 | File offset error |
| ERROR_UNIKEY_FS_ERR_OPEN_FILE | 247 | Failed to open file |
Append Data to the End-Of-File
API Prototype
function UniKey_FS_File_Append_Data(pHandle: pWord; len: pLongWord; buffer: pByteArray): DWORD; stdcall;
Description
Append data to the end-of-file.
Parameters
| Parameter | Meaning |
|---|---|
| pHandle | [in] Device handle |
| len | [in] The length of the data to be appended |
| buffer | [in] Data to append |
Return values
| Result | Value | Meaning |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_NO_MEMORY | 244 | Not enough free memory |
Read File Data
API Prototype
function UniKey_FS_File_Read_Data(pHandle: pWord; offset: pLongWord; len: pLongWord; buffer: pByteArray): DWORD; stdcall;
Description
Read file data.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| offset | [in] Read address |
| len | [in] Length of data to be read |
| buffer | [out] Read data |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_FS_FILE_OFFSET | 242 | File offset error |
| ERROR_UNIKEY_FS_ERR_OPEN_FILE | 247 | Failed to open file |
Close Files
API Prototype
function UniKey_FS_File_Close(pHandle: pWord; filename: pByteArray): DWORD; stdcall;
Description
Close files.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filename | [in] Filename |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
Get File List
API Prototype
function UniKey_FS_File_Get_List(pHandle: pWord; filecount: pLongWord; filelist: pByteArray): DWORD; stdcall;
Description
Get list of files on the UniKey Drive.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filecount | [out] The number of files |
| filelist | [out] File list |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
Get File Size
API Prototype
function UniKey_FS_File_Get_Size(pHandle: pWord; filesize: pLongWord): DWORD; stdcall;
Description
Get the file size.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| filesize | [out] The size of the file |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
User Reset File System Password
API Prototype
function UniKey_FS_Set_Password(pHandle: pWord; PW1: pLongWord; PW2: pLongWord; PW3: pLongWord; PW4: pLongWord): DWORD; stdcall;
Description
Allows a user to reset the file system password.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| PW1 | [in] Password 1 |
| PW2 | [in] Password 2 |
| PW3 | [in] Password 3 |
| PW4 | [in] Password 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_GENERATE_NEW_PASSWORD | 225 | Error generating new password |
A password reset can only be successfully done after initializing the file system.
Generate RSA Key
API Prototype
function UniKey_RSA_Generate_Key(pHandle: pWord; KeyIndex: pWord): DWORD; stdcall;
Description
UniKey Drive has encryption and decryption modules with 1024-bit RSA keys. Calling this function can generate a 1024-bit RSA key.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [out] Return the handle generated key |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid |
Generate a DES Key
API Prototype
function UniKey_DES_Generate_Key(pHandle: pWord; KeyIndex: pWord): DWORD; stdcall;
Description
Calling this function can generate a DES key.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [out] Return the handle generated key |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid |
RSA Get Number of Generated Keys
API Prototype
function UniKey_RSA_Get_Key_Counts(pHandle: pWord; KeyIndex: pLongWord): DWORD; stdcall;
Description
Get the number of RSA keys that are generated.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [out] Key count |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid |
DES Get Number of Generated Keys
API Prototype
function UniKey_DES_Get_Key_Counts(pHandle: pWord; KeyIndex: pLongWord): DWORD; stdcall;
Description
Get the number of DES keys that are generated.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [out] Key count |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid |
RSA Encryption
API Prototype
function UniKey_RSA_Encrypt(pHandle: pWord; KeyIndex: pWord; Encrypt_Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
Description
Encrypt data using RSA.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [in] Encrypt and decrypt using the key handle |
| Encrypt_Len | [in] Data length to be encrypted |
| Buffer | [in/out] Input plain text and output encrypted text |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_ENCRYPT_FAILED | 228 | Could not encrypt data |
RSA Decryption
API Prototype
function UniKey_RSA_Decrypt(pHandle: pWord; KeyIndex: pWord; Encrypt_Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
Description
Decrypt data using RSA.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in]Device handle |
| KeyIndex | [in] Encrypt and decrypt using the key handle |
| Decrypt_Len | [in] Length of data to be decrypted |
| Buffer | [in/out] Input encrypted text and output plain text. |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_DECRYPT_FAILED | 229 | Could not decrypt data |
| ERROR_UNIKEY_KEY_INDEX | 239 | The key handle is invalid |
DES Encryption
API Prototype
function UniKey_DES1_Encrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
function UniKey_DES2_Encrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
function UniKey_DES3_Encrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
Description
Encrypt data using DES.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| EncryptMode | [in] Block cipher mode of operation |
| KeyIndex | [in] Encrypt and decrypt using the key handle |
| Len | [in] Length of data to be encrypted |
| Buffer | [in/out] Input plain text and output encrypted text. |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_ENCRYPT_FAILED | 228 | Could not encrypt data |
| ERROR_UNIKEY_KEY_INDEX | 239 | The key handle is invalid |
DES Decryption
API Prototype
function UniKey_DES1_Decrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
function UniKey_DES2_Decrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
function UniKey_DES3_Decrypt(pHandle: pWord; EncryptMode: pWord; KeyIndex: pWord; Len: pLongWord; Buffer: pByteArray): DWORD; stdcall;
Description
Encrypt data using DES.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| DecryptMode | [in] Block cipher mode of operation |
| KeyIndex | [in] Encrypt and decrypt using the key handle |
| Len | [in] Length of data to be decrypted |
| Buffer | [in/out] Input encrypted text and output plain text. |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_DECRYPT_FAILED | 229 | Could not decrypt data |
| ERROR_UNIKEY_KEY_INDEX | 239 | The key handle is invalid |
Delete RSA Key
API Prototype
function UniKey_RSA_Del_Key(pHandle: pWord; KeyIndex: pWord): DWORD; stdcall;
Description
Delete a RSA key.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [in] The handle to be deleted |
Return values
| Result | Value | Meaning |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid 0 > KeyIndex > 3 |
Delete DES Key
API Prototype
function UniKey_DES_Del_Key(pHandle: pWord; KeyIndex: pWord): DWORD; stdcall;
Description
Delete a DES key.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| KeyIndex | [in] Key handle to be deleted |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_KEY_INDEX | 239 | The handle of the key is invalid 0 > KeyIndex > 14 |
Get User Counts
API Prototype
function UniKey_Get_UserCount(pHandle: pWord; Count: pWord): DWORD; stdcall;
Description
UniKey Drive can enable 32 concurrent users to log in. This function can be called to get the number of users logged in.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| Count | [out] Number of users logged in |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
Only Allow One User to Log in
API Prototype
function Unikey_Logon_Single(pHandle: pWord; pPassword1: pLongWord; pPassword2: pLongWord; pPassword3: pLongWord; pPassword4: pLongWord): DWORD; stdcall;
Description
After calling this function, the UniKey Drive will only allow the active user to log in, other users will not be allowed to log in.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
| pPassword1 | [in] Password 1 |
| pPassword2 | [in] Password 2 |
| pPassword3 | [in] Password 3 |
| pPassword4 | [in] Password 4 |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
| ERROR_UNIKEY_INVALID_PASSWORD_OR_ID | 202 | Wrong password or UniKey HID |
Log off the Active User
API Prototype
function UniKey_Logoff(pHandle: pWord):DWORD; stdcall;
Description
After calling this function, the active user will be logged out, does not affect other users’ login status.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |
Log off all Users
API Prototype
function UniKey_Logoff_All(pHandle: pWord): DWORD; stdcall;
Description
After calling this function, all users will be logged off.
Parameters
| Parameter | Description |
|---|---|
| pHandle | [in] Device handle |
Return values
| Result | Value | Description |
|---|---|---|
| SUCCESS | 0 | Success |