UniKey API Reference for C Language: Difference between revisions

From SecuTech Wiki
Jump to navigationJump to search
Joseph (talk | contribs)
No edit summary
Bao (talk | contribs)
Added lock and unlock functions
 
(170 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[category:UniKey APIs]]
[[category:UniKey API]]


<br>
== UniKey API Reference ==
 
A WORD is defined to be a 16-bit unsigned integer, while a DWORD is a 32-bit unsigned integer. These should be defined as types of that size regardless of platform.
 
=== Find a UniKey dongle  ===
 
'''API Prototype'''
 
<code>long UniKey_Find(WORD* pHandle, DWORD* pSetting1, DWORD* pSetting2);</code>


== Find a UniKey dongle  ==
'''Description'''


'''API Prototype'''<br>
Check if a specific UniKey is attached to the USB port. This is the first API used to start a UniKey session.
<code>long UniKey_Find( WORD* pHandle ,<br>DWORD* pSetting1 , <br>DWORD* pSetting2 )&nbsp;;</code>


'''Description'''<br>
'''Parameters'''
Check if a specific UniKey is attached to the USB port. This is the first API to start a UniKey session.


'''Parameters'''<br>
<table class="wikitable">
<table border="1">
<tr>
<tr>
<td>Parameter</td>
<th>Parameter</th>
<td>Meaning</td>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
Line 22: Line 27:
</tr>
</tr>
<tr>
<tr>
<td>*pSetting1</td>
<td rowspan="2">*pSetting1</td>
<td>*[in] Working Mode (UniKey PRO only), useless for UniKey STD</td>
<td>[in] Working mode (UniKey PRO only), useless for UniKey STD</td>
</tr>
</tr>
<tr>
<tr>
<td></td>
<td>[out] Hardware ID</td>
<td>[out] Hardware ID</td>
</tr>
</tr>
<tr>
<tr>
<td>*pSetting2</td>
<td rowspan="2">*pSetting2</td>
<td>*[in] Access Mode (UniKey PRO only), useless for UniKey STD(UniKey PRO only)</td>
<td>[in] Access mode (UniKey PRO only), useless for UniKey STD</td>
</tr>
</tr>
<tr>
<tr>
<td></td>
<td>[out] Number of dongles attached, useless for UniKey STD</td>
<td>[out] Number of dongle attached , useless for UniKey STD</td>
</tr>
</tr>
</table>
</table>


'''Return values'''<br>
'''Return values'''
<table border="1">
 
<table class="wikitable">
<tr>
<tr>
<td>Marco</td>
<th>Result</th>
<td>Value</td>
<th>Value</th>
<td>Meaning</td>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
Line 52: Line 56:
</tr>
</tr>
<tr>
<tr>
<td>ERROR_UNIKEY_NO_UNIEKY</td>
<td>ERROR_UNIKEY_NOT_FOUND</td>
<td>200</td>
<td>200</td>
<td>No UniKey dongle</td>
<td>No UniKey dongle</td>
</tr>
</tr>
</table>
</table>
----
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.
----


<br>
<br>


== Find the Next UniKey dongle ==
=== Find the Next UniKey dongle ===
 
'''API Prototype'''
 
<code>long UniKey_Find_Next(WORD* pHandle, DWORD* pSetting1, DWORD* pSetting2);</code>


'''API Prototype'''<br>
'''Description'''
<code>Long UniKey_Find_Next( WORD* pHandle ,<br>DWORD* pSetting1 , <br>DWORD* pSetting2 )&nbsp;;</code>


'''Description'''<br>
Check if another UniKey is attached to the USB port.  
Check if another UniKey is attached to the USB port.  


'''Parameters'''<br>
'''Parameters'''
<table border="1">
 
<table class="wikitable">
<tr>
<tr>
<td>Parameter</td>
<th>Parameter</th>
<td>Meaning</td>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
Line 79: Line 91:
</tr>
</tr>
<tr>
<tr>
<td>*pSetting1</td>
<td rowspan="2">*pSetting1</td>
<td>*[in] Working Mode (UniKey PRO only), useless for UniKey STD</td>
<td>[in] Working Mode (UniKey PRO only), useless for UniKey STD</td>
</tr>
</tr>
<tr>
<tr>
<td></td>
<td>[out] Hardware ID</td>
<td>[out] Hardware ID</td>
</tr>
</tr>
<tr>
<tr>
<td>*pSetting2</td>
<td rowspan="2">*pSetting2</td>
<td>*[in] Access Mode (UniKey PRO only), useless for UniKey STD(UniKeyPro only)</td>
<td>[in] Access Mode (UniKey PRO only), useless for UniKey STD</td>
</tr>
</tr>
<tr>
<tr>
<td></td>
<td>[out] Number of dongles attached , useless for UniKey STD</td>
<td>[out] Number of dongle attached , useless for UniKey STD</td>
</tr>
</tr>
</table>
</table>


'''Return values'''<br>
'''Return values'''
<table border="1">
 
<table class="wikitable">
<tr>
<tr>
<td>Marco</td>
<th>Result</th>
<td>Value</td>
<th>Value</th>
<th>Meaning</th>
</tr>
</tr>
<tr>
<tr>
<td>SUCCESS</td>
<td>SUCCESS</td>
<td>0</td>
<td>0</td>
<td>Success</td>
</tr>
</tr>
<tr>
<tr>
<td>ERROR_UNIKEY_NOMORE </td>
<td>ERROR_UNIKEY_NOMORE</td>
<td>214</td>
<td>214</td>
<td>No more dongles found</td>
</tr>
</tr>
<tr>
<tr>
<td>ERROR_UNIKEY_NEED_FIND</td>
<td>ERROR_UNIKEY_NEED_FIND</td>
<td>215</td>
<td>215</td>
<td>Find needs to be called before Find_Next</td>
</tr>
</tr>
</table>
</table>


== <br>Logon UniKey Dongle  ==
<br>


&nbsp;
=== Log on to UniKey Dongle  ===


'''API Prototype'''<br><code>long UniKey_User_Logon( WORD* pHandle , <br>WORD* pPassword1 , <br>WORD* pPassword2 )&nbsp;;</code><br>-------------------------------------------------------------------------------------------
'''API Prototype'''


For UniKey Drive, the '''API Prototype''' is UniKey_User_Logon (WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2); <br>-------------------------------------------------------------------------------------------<br>'''Description''' <br>Logon a UniKey dongle with specified passwords. This API should be called in the released software in order to improve security.
<code>long UniKey_User_Logon(WORD* pHandle, WORD* pPassword1, WORD* pPassword2);</code>


'''Parameters'''<br>
For UniKey Drive, the API Prototype is
<table border="1">
 
<code>UniKey_User_Logon(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2);</code>
 
'''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'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<tr>
<td>Parameter</td>
<td>*pHandle</td>
<td>Meaning</td>
<td>[out] Dongle handle</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword1</td>
<td>*pPassword1</td>
<td>[in]Password  1</td>
<td>[in] Password  1</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword2</td>
<td>*pPassword2</td>
<td>[in]Password  2</td>
<td>[in] Password  2</td>
</tr>
<tr>
<td>*pHandle</td>
<td>[out] Dongle handle</td>
</tr>
</tr>
</table>
</table>


'''Return values'''<br>
'''Return values'''
<table border="1">
 
<table class="wikitable">
<tr>
<tr>
<td>Marco</td>
<th>Result</th>
<td>Value</td>
<th>Value</th>
<td>Meaning</td>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
Line 164: Line 189:
<td>ERROR_UNIKEY_INVALID_PASSWORD</td>
<td>ERROR_UNIKEY_INVALID_PASSWORD</td>
<td>201</td>
<td>201</td>
<td>UniKey dongle found, but Basic passwords are incorrect</td>
<td>Found UniKey dongle, but basic passwords (password 1 and 2) are incorrect</td>
</tr>
</tr>
<tr>
<tr>
Line 175: Line 200:
<br>
<br>


== Logon UniKey Dongle in vendor mode  ==
=== Log on to UniKey Dongle in vendor mode  ===
 
'''API Prototype'''
 
<code>long UniKey_Vender_Logon(WORD* pHandle, WORD* pPassword1, WORD* pPassword2, WORD* pPassword3, WORD* pPassword4);</code>
 
For UniKey Drive, the API Prototype is


<br>'''API Prototype'''<br><code>long UniKey_Vender_Logon( WORD* pHandle ,<br>WORD* pPassword1 ,<br>WORD* pPassword2 ,<br>WORD* pPassword3 ,<br>WORD* pPassword4 )&nbsp;;</code><br>---------------------------------------------------------------------------------------------------<br>For UniKey Drive, the '''API Prototype''' is UniKey_Vender_Logon(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2, DWORD* pPassword3, DWORD* pPassword4);<br>---------------------------------------------------------------------------------------------------
<code>UniKey_Vender_Logon(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2, DWORD* pPassword3, DWORD* pPassword4);</code>


'''Description''' <br>Logon a UniKey dongle in vendor mode with specified passwords. This API helps software vendors to logon the UniKey dongle in vendor mode, and get the full permission to UniKey dongle.<br>---------------------------------------------------------------------------------------------------<br>We do NOT advise you to enclose this API in the final released software. This API is only for software vendor’s usage.<br>--------------------------------------------------------------------------------------------------<br>If password3 or password4 is wrong while password1 and password2 is correct, the dongle is also logged on in user mode automatically. <br>---------------------------------------------------------------------------------------------------
'''Description'''


'''Parameters'''<br>
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.
<table border="1">
 
 
----
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'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<tr>
<td>Parameter</td>
<td>*pHandle</td>
<td>Meaning</td>
<td>[out] Dongle handle</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword1</td>
<td>*pPassword1</td>
<td>[in]Password 1</td>
<td>[in] Password 1</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword2</td>
<td>*pPassword2</td>
<td>[in]Password 2</td>
<td>[in] Password 2</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword3</td>
<td>*pPassword3</td>
<td>[in]Password 3</td>
<td>[in] Password 3</td>
</tr>
</tr>
<tr>
<tr>
<td>*pPassword4</td>
<td>*pPassword4</td>
<td>[in]Password 4</td>
<td>[in] Password 4</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NOT_FOUND</td>
<td>200</td>
<td>No UniKey dongle</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_PASSWORD</td>
<td>201</td>
<td>Found UniKey dongle, but basic passwords (password 1 and 2) are incorrect</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID</td>
<td>202</td>
<td>Wrong password or UniKey HID</td>
</tr>
</table>
 
<br>
 
=== Log off the UniKey dongle  ===
 
'''API Prototype'''
 
<code>long UniKey_Logoff(WORD* pHandle);</code>
 
'''Description'''
 
Log off a UniKey dongle with a specific handle; this API should be called at the end of a UniKey session.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
<td>*pHandle</td>
<td>*pHandle</td>
<td>[out] Dongle handle</td>
<td>[in] Dongle handle</td>
</tr>
</tr>
</table>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NOT_FOUND 200 No UniKey dongle<br>ERROR_UNIKEY_INVALID_PASSWORD 201 Found UniKey dongle, but Basic passwords are incorrect<br>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID 202 Wrong password or UniKey HID
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NOT_FOUND</td>
<td>200</td>
<td>No UniKey dongle</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>


<br>
<br>


== Logoff the UniKey dongle ==
=== Get the UniKey Dongle's Type ===


<br>'''API Prototype'''<br><code>long UniKey_Logoff( WORD* pHandle )&nbsp;;</code>
'''API Prototype'''


'''Description'''<br>Logoff a UniKey dongle with a specific handle. This API should be called at the end of UniKey session.
<code>long UniKey_Get_Type(WORD* pHandle, DWORD* type);</code>  


'''Parameters'''<br>
'''Description'''
<table border="1">
 
<code>UniKey_Get_Type</code> can help you get the type of the UniKey dongle.<br>
This functions return value will help to indicate the type of the UniKey dongle.
 
<table class="wikitable">
<tr>
<th>Type</th>
<th>Code</th>
</tr>
<tr>
<tr>
<td>Parameter</td>
<td>UNIKEY_TYPE_TIME</td>
<td>Meaning</td>
<td>101</td>
</tr>
<tr>
<td>UNIKEY_TYPE_PRO</td>
<td>102</td>
</tr>
<tr>
<td>UNIKEY_TYPE_STD</td>
<td>103</td>
</tr>
</table>
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
<td>*pHandle</td>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*type</td>
<td>[out] The value indicating the type of your UniKey dongle</td>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_GET_TYPE</td>
<td>256</td>
<td>UniKey Get Type Error</td>
</tr>
</tr>
</table>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NOT_FOUND 200 No UniKey dongle<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle
<br>
 
=== Read UniKey dongle memory  ===


== <br>Get the UniKey dongle 's Type  ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Get_Type( WORD* pHandle , <br>DWORD* type )&nbsp;;</code>  
<code>long UniKey_Read_Memory(WORD* pHandle, WORD* pStartAddress, WORD* pBufferLength, BYTE* pBuffer);</code>  


'''Description'''<br>UniKey_Get_Type can help you get the type of the UniKey dongle.<br>The return value of type will indicate the type of the UniKey dongle.<br>UNIKEY_TYPE_TIME 101<br>UNIKEY_TYPE_PRO 102<br>UNIKEY_TYPE_STD 103
'''Description'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*type [out] The value indicating the type of your UniKey dongle  
Read the contents of memory; this API needs to be called after logging in to a UniKey dongle.


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_GET_TYPE 237 UniKey Get Type Error  
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Offset of Memory</td>
</tr>
<tr>
<td>*pBufferLength</td>
<td>[in] Number of bytes to read</td>
</tr>
<tr>
<td>*pBuffer</td>
<td>[out] Pointer to the buffer containing the data to be read</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_READ_MEMORY</td>
<td>207</td>
<td>Read Error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>


<br>
<br>


== Read UniKey dongle memory  ==
=== Write to UniKey dongle memory  ===
 
'''API Prototype'''
 
<code>long UniKey_Write_Memory(WORD* pHandle, WORD* pStartAddress, WORD* pBufferLength, BYTE* pBuffer);</code>
 
'''Description'''
 
Write data into memory; this API needs to be called after logging on to a UniKey dongle.


<br>'''API Prototype'''<br><code>long UniKey_Read_Memory( WORD* pHandle ,<br>WORD* pStartAddress ,<br>WORD* pBufferLength , <br>BYTE* pBuffer )&nbsp;;</code>  
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Offset of the memory</td>
</tr>
<tr>
<td>*pBufferLength</td>
<td>[in] Number of bytes to write</td>
</tr>
<tr>
<td>*pBuffer</td>
<td>[in] Pointer to the buffer containing the data to be written</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_MEMORY</td>
<td>207</td>
<td>Write Error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_VERIFY_ADV_PASSWORD</td>
<td>223</td>
<td>Advanced passwords (password 3 and 4) not verified</td>
</tr>
</table>
 
 
----
To write the last 2k memory (for 2048 – 4096), you need to verify all 4 passwords (vendor mode) to obtain the requisite permission.
----
 
 
----
<code>UniKey_Read_Memory</code> and <code>UniKey_Write_Memory</code> 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.
----


<br>
<br>


'''Description''' <br>Read the contents of the Memory. This API needs to be called after logon of a UniKey dongle.
=== Generate a Random Number ===


'''Parameters'''<br>Parameter Meaning<br>*handle*pHandle [in] Dongle handle<br>*pStartAddress [in] Offset of Memory<br>*pBufferLenght [in] Number of bytes to read<br>pBbuffer [out] Pointer to the buffer containing the data to be read
'''API Prototype'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_READ_MEMORY 207 Read Error<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_NEED_OPEN 215 No logon dongle before operating dongle  
<code>long UniKey_Random(WORD* pHandle, WORD* pReturn1, WORD* pReturn2, WORD* pReturn3, WORD* pReturn4);</code>
 
'''Description'''
 
Generates random numbers from the dongle.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pReturn1</td>
<td>[out] Random number</td>
</tr>
<tr>
<td>*pReturn2</td>
<td>[out] Random number</td>
</tr>
<tr>
<td>*pReturn3</td>
<td>[out] Random number</td>
</tr>
<tr>
<td>*pReturn4</td>
<td>[out] Random number</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_RANDOM</td>
<td>209</td>
<td>Random number error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>
 
 
----
<code>UniKey_Random</code> 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.
----


<br>
<br>


== Write to UniKey dongle memory  ==
=== Generate Seed Code Return Values ===
 
'''API Prototype'''
 
<code>long UniKey_Seed(WORD* pHandle, DWORD* pSeed, WORD* pReturn1, WORD* pReturn2, WORD* pReturn3, WORD* pReturn4);</code>
 
'''Description'''


<br>'''API Prototype'''<br><code>long UniKey_Write_Memory( WORD* pHandle ,<br>WORD* pStartAddress , <br>WORD* pBufferLength , <br>BYTE* pBuffer )&nbsp;;</code>
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.


'''Description'''<br>Write data into the memory. This API needs to be called after logging on to a UniKey dongle.
'''Parameters'''


'''Parameters'''<br>Parameter Meaning<br>*handle*pHandle [in] Dongle handle<br>*pStartAddress [in] Offset of the memory<br>*pBufferLength [in] Number of bytes to write<br>pBbuffer [in] Pointer to the buffer containing the data to be written
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pSeed</td>
<td>[in] Seed code</td>
</tr>
<tr>
<td>*pReturn1</td>
<td>[out] Return code 1</td>
</tr>
<tr>
<td>*pReturn2</td>
<td>[out] Return code 2</td>
</tr>
<tr>
<td>*pReturn3</td>
<td>[out] Return code 3</td>
</tr>
<tr>
<td>*pReturn4</td>
<td>[out] Return code 4</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_WRITE_MEMORY 207 Write Error<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_VERIFY_ADV_PASSWORD 223 Advanced passwords (password3 and passowrd4) not verified
'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_SEED</td>
<td>210</td>
<td>Seed code error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>
----
<code>UniKey_Seed</code> 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.
----
----


<br>To write the last 2k memory (for 2048 – 4096), you need to verify all the 4 passwords (vendor mode) to obtain full permission to the dongle.<br>--------------------------------------------------------------------------------------------------
<br>
 
=== Write Software ID ===
 
'''API Prototype'''


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.<br>--------------------------------------------------------------------------------------------------
<code>long UniKey_Write_SoftID(WORD* pHandle, DWORD* pSoftID);</code>  


== <br>Generate a Random Number  ==
'''Description'''


<br>'''API Prototype'''<br><code>long UniKey_Random( WORD* pHandle ,<br>WORD* pReturn1 ,<br>WORD* pReturn2 ,<br>WORD* pReturn3 , <br>WORD* pReturn4 )&nbsp;;</code>
Write the vendor-defined software ID.


'''Description'''<br>Generate a random number from the dongle.
'''Parameters'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pReturn1 [out] Random number<br>*pReturn2 [out] Random number<br>*pReturn3 [out] Random number<br>*pReturn4 [out] Random number
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pSoftID</td>
<td>[in] Software ID</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_SET_SOFTID</td>
<td>203</td>
<td>Set software ID error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_RANDOM 209 Random number Error


----
----
You need to verify all 4 passwords (vendor mode) to write the software ID to the dongle.
----
<br>


<br>UNIKEY_RANDOM is to generate a random number inside the dongle. The UniKey dongle computing engine generates the number and the hardware of the dongle is the seed for the random number.<br>--------------------------------------------------------------------------------------------------
=== Read Software ID ===


== <br>Generate Seed Code '''Return values''' ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Seed( WORD* pHandle ,<br>DWORD* pSeed ,<br>WORD* pReturn1 , <br>WORD* pReturn2 , <br>WORD* pReturn3 , <br>WORD* pReturn4 )&nbsp;;</code>  
<code>long UniKey_Read_SoftID(WORD* pHandle, DWORD* pSoftID);</code>  


'''Description'''<br>Get return codes from the input of a seed code. This API return for values which are related to pSeed and UniKey dongle’s password.
'''Description'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pSeed [in] Seed Code<br>*pReturn1 [out] Return Code 1<br>*pReturn2 [out] Return Code 2<br>*pReturn3 [out] Return Code 3<br>*pReturn4 [out] Return Code 4
Read the user-defined software ID.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pSoftID</td>
<td>[out] Software ID</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_SEED 210 Seed code Error


----
<code>UniKey_Write_SoftID</code> and <code>UniKey_Read_SoftID</code> provide a means to make a soft (write-able) ID for each software. You can write different software ID for each software and call <code>UNIKEY_READ_SOFTID</code> to check if the software ID is correct.
----
----


<br>UniKey_Seed generate a set of seed codes. All of these seed codes are based on the password. It provides another method to verify the password and check the insertion of the dongle. Apart from this, the seed codes can be used to involve in other computation, for example, you use the seed returned as a 64-bit long encryption key. <br>---------------------------------------------------------------------------------------------------
<br>


== <br>Write the Soft ID ==
=== Set a UniKey License module ===


<br>'''API Prototype'''<br><code>long UniKey_Write_SoftID( WORD* pHandle , <br>DWORD* pSoftID )&nbsp;;</code>
'''API Prototype'''


'''Description''' <br>Write the vendor defined SoftID.
<code>long UniKey_Set_Module(WORD* pHandle, WORD* pModule, WORD* pValue, WORD* pDecrease);</code>  


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pSoftID [in] Soft ID
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_SET_SOFTID 203 Set UniKey ID wrong<br>---------------------------------------------------------------------------------------------------
To write a value to a specific UniKey license module and set the Decrement attribute.


You need to verify all 4 passwords (vendor mode) to write the SoftID.<br>---------------------------------------------------------------------------------------------------
'''Parameters'''


Read Soft ID <br>'''API Prototype'''<br><code>long UniKey_Read_SoftID( WORD* pHandle ,<br>DWORD* pSoftID )&nbsp;;</code>  
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pValue</td>
<td>[in] License module unit value</td>
</tr>
<tr>
<td>*pDecrease</td>
<td>[in] Decrement attribute (1 = allowed, 0 = not allowed)</td>
</tr>
</table>


'''Description'''<br>Read the user defined SoftID.
'''Return values'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pSoftID [out] Soft ID
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>202</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>
 
 
----
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.
----
 
<br>
 
=== Get a UniKey License module  ===
 
'''API Prototype'''
 
<code>long UniKey_Get_Module(WORD* pHandle, WORD* pModule, WORD* pValue);</code>
 
'''Description'''
 
Get a value from a specific UniKey license module.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Module Number</td>
</tr>
<tr>
<td>*pValue</td>
<td>[out] Return the value in module</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>202</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle


----
----
You need to verify 2 passwords (user mode) to get a module value successfully.
----
<br>
=== Check a UniKey License module  ===
'''API Prototype'''


<br>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.<br>---------------------------------------------------------------------------------------------------<br><br>
<code>long UniKey_Check_Module(WORD* pHandle, WORD* pModule, WORD* pValue, WORD* pDecrease);</code>  


== Set a UniKey License module  ==
'''Description'''


<br>'''API Prototype'''<br><code>long UniKey_Set_Module( WORD* pHandle ,<br>WORD* pModule ,<br>WORD* pValue , <br>WORD* pDecrease )&nbsp;;</code>
Read the attributes of a specific UniKey license module.


'''Description'''<br>To write a value to a specific UniKey license module and set the Decrement attribute.
'''Parameters'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module Number<br>*pValue [in] License module Unit Value<br>*pDecrease [in] Decreasing attribute. If decreasing is allowed (1 = allowed, 0 = not allowed)
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pValue</td>
<td>[out] Validity (1 = license module value is not zero)</td>
</tr>
<tr>
<td>*pDecrease</td>
<td>[out] Decrement attribute (1 = license module can be decreased)</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>202</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>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.
----
----


<br>A successful operation will result in license module unit # “*pModule” storing value “*pValue” and the Decrement attribute set to “0” or “1” <br>---------------------------------------------------------------------------------------------------


----
<code>UniKey_Set_Module</code> and <code>UniKey_Check_Module</code> 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 <code>UniKey_Set_Module</code> 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.
----
----


You need verify 4 passwords (vendor mode) to set a module value successfully. <br>---------------------------------------------------------------------------------------------------
<br>


&nbsp;
=== Write Arithmetic  ===


== Get a UniKey License module  ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Get_Module( WORD* pHandle ,<br>WORD* pModule , <br>WORD* pValue )&nbsp;;</code>  
<code>long UniKey_Write_Arithmetic(WORD* pHandle, WORD* pStartAddress, BYTE* pBuffer);</code>  


'''Description'''<br>Get a value from a specific UniKey license module.
'''Description'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] Module Number<br>*pValue [out] Return the value in module
Write user-defined mathematical algorithms.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Offset of first instruction</td>
</tr>
<tr>
<td>*pBuffer</td>
<td>[in] Pointer to the algorithm command string</td>
</tr>
</table>
 
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_BAD_COMMAND</td>
<td>217</td>
<td>Arithmetic instruction error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_UNKNOWN_OPCODE</td>
<td>218</td>
<td>Arithmetic operator error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_BEGIN</td>
<td>219</td>
<td>Constant numbers can't be used on first arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_END</td>
<td>220</td>
<td>Constant numbers can't be used on last arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_VALUE_OVERFLOW</td>
<td>221</td>
<td>Constant numbers > 63 will cause an overflow</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error


----
A successful operation will result in a user-defined algorithm containing the algorithm command string from the buffer.
----
----


You need verify 2 passwords (user mode) to get a module value successfully. <br>---------------------------------------------------------------------------------------------------


&nbsp;
----
<code>UniKey_Write_Arithmetic</code> 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 <code>UniKey_Write_Arithmetic</code>
----


== Check a UniKey License module  ==
<br>


<br>'''API Prototype'''<br><code>long UniKey_Check_Module( WORD* pHandle ,<br>WORD* pModule ,<br>WORD* pValue , <br>WORD* pDecrease )&nbsp;;</code>
=== User-Defined Algorithm Calculate 1 ===


'''Description'''<br>Read the attributes of a specific UniKey license module.
'''API Prototype'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module Number<br>*pValue [out] Validity (1 = license module value is not zero)<br>*pDecrease [out] Decrement attribute (1 = license module can be decreased)
<code>long UniKey_Calculate1(WORD* pHandle, DWORD* pStartAddress, DWORD* pModule, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);</code>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error<br>---------------------------------------------------------------------------------------------------<br>A successful operation will result in “*pValue” with value from the Validity (1 = license module value is not zero), and “*pDecrease” with the value from the Decrement attribute (1 = license module can be decreased).
'''Description'''


The value of a license module cannot be read out directly and it is invisible to end users. <br>---------------------------------------------------------------------------------------------------<br>---------------------------------------------------------------------------------------------------<br>UniKey_Set_Module and UniKey_Check_Module provide an easy mean to implement software limitation. For example, if you want to set a software can be only executed 3 times, so you can call UNIKEY_SET_MODULE to set a license module (let us say license module 0) as 3. And when 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 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 module in the UniKey dongle. Let us say the 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, B, you just need to enable the license module 0 and 1, and leave 2 and 3 as zero. So only function module A and B can be executed. If the customer buys more function, you can use UniKey remote update function to update the dongle remotely. <br>--------------------------------------------------------------------------------------------------
Return the results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE1 function.  


== <br>Write Arithmetic  ==
'''Parameters'''


<br>'''API Prototype'''<br><code>long UniKey_Write_Arithmetic( WORD* pHandle , <br>WORD* pStartAddress , <br>BYTE* pBuffer )&nbsp;;</code>  
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Start point of calculation</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pRegA</td>
<td>[in, out] Register A</td>
</tr>
<tr>
<td>*pRegB</td>
<td>[in, out] Register B</td>
</tr>
<tr>
<td>*pRegC</td>
<td>[in, out] Register C</td>
</tr>
<tr>
<td>*pRegD</td>
<td>[in, out] Register D</td>
</tr>
</table>
 
'''Return values'''


'''Description'''<br>Write user-defined mathematical algorithms.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_BAD_COMMAND</td>
<td>217</td>
<td>Arithmetic instruction error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_UNKNOWN_OPCODE</td>
<td>218</td>
<td>Arithmetic operator error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_BEGIN</td>
<td>219</td>
<td>Constant numbers can't be used on first arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_END</td>
<td>220</td>
<td>Constant numbers can't be used on last arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_VALUE_OVERFLOW</td>
<td>221</td>
<td>Constant numbers > 63 will cause an overflow</td>
</tr>
</table>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pStartAddress [in] Offset of first instruction <br>*pBuffer [in] Pointer to the algorithm command string


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_AR_BAD_COMMAND 217 Arithmetic instruction Error<br>ERROR_UNIKEY_AR_UNKNOWN_OPCODE 218 Arithmetic operator Error<br>ERROR_UNIKEY_AR_WRON_GBEGIN 219 Const number can't use on first arithmetic instruction<br>ERROR_UNIKEY_AR_WRONG_END 220 Const number can't use on last arithmetic instruction<br>ERROR_UNIKEY_AR_VALUE_OVERFLOW 221 Const number &gt; 63<br>
----
When the calculation starts, the values of other internal registers are listed in the table below.<br>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.
----
 
 
<table class="wikitable">
<tr>
<th>Internal Register</th>
<th>Description</th>
</tr>
<tr>
<td>E</td>
<td>High-order byte of reversed hardware ID</td>
</tr>
<tr>
<td>F</td>
<td>Low-order byte of reversed hardware ID</td>
</tr>
<tr>
<td>G</td>
<td>Value stored in license module *pModule</td>
</tr>
<tr>
<td>H</td>
<td>Random number</td>
</tr>
</table>
 
 
----
Examples:
<br>If the internal algorithm is A = B + C, then the call result is *pRegA = *pRegB + *pRegC
<br>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
<br>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.
----
 
<br>
 
=== User-Defined Algorithm Calculate 2  ===
 
'''API Prototype'''
 
<code>long UniKey_Calculate2(WORD* pHandle, DWORD* pStartAddress, DWORD* pSeed, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);</code>
 
'''Description'''
 
Return the results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE2 function.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Start point of calculation</td>
</tr>
<tr>
<td>*pSeed</td>
<td>[in] Seed code (32-bit)</td>
</tr>
<tr>
<td>*pRegA</td>
<td>[in, out] Register A</td>
</tr>
<tr>
<td>*pRegB</td>
<td>[in, out] Register B</td>
</tr>
<tr>
<td>*pRegC</td>
<td>[in, out] Register C</td>
</tr>
<tr>
<td>*pRegD</td>
<td>[in, out] Register D</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_BAD_COMMAND</td>
<td>217</td>
<td>Arithmetic instruction error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_UNKNOWN_OPCODE</td>
<td>218</td>
<td>Arithmetic operator error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRON_GBEGIN</td>
<td>219</td>
<td>Constant numbers can't be used on first arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_END</td>
<td>220</td>
<td>Constant numbers can't be used on last arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_VALUE_OVERFLOW</td>
<td>221</td>
<td>Constant numbers > 63 will cause an overflow</td>
</tr>
</table>
 
 
----
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.
----
 
 
<table class="wikitable">
<tr>
<th>Internal Register</th>
<th>Description</th>
</tr>
<tr>
<td>E</td>
<td>Seed result 1</td>
</tr>
<tr>
<td>F</td>
<td>Seed result 2</td>
</tr>
<tr>
<td>G</td>
<td>Seed result 3</td>
</tr>
<tr>
<td>H</td>
<td>Seed result 4</td>
</tr>
</table>
 
<br>
 
=== User-Defined Algorithm Calculate 3  ===
 
'''API Prototype'''
 
<code>long UniKey_Calculate3(WORD* pHandle, DWORD* pStartAddress, DWORD* pModule, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);</code>
 
'''Description'''
 
Return results of a calculation performed in the UniKey, using input provided by the developer and the CALCULATE3 function.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pStartAddress</td>
<td>[in] Start point of calculation</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pRegA</td>
<td>[in, out] Register A</td>
</tr>
<tr>
<td>*pRegB</td>
<td>[in, out] Register B</td>
</tr>
<tr>
<td>*pRegC</td>
<td>[in, out] Register C</td>
</tr>
<tr>
<td>*pRegD</td>
<td>[in, out] Register D</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_BAD_COMMAND</td>
<td>217</td>
<td>Arithmetic instruction error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_UNKNOWN_OPCODE</td>
<td>218</td>
<td>Arithmetic operator error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRON_GBEGIN</td>
<td>219</td>
<td>Constant numbers can't be used on first arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_WRONG_END</td>
<td>220</td>
<td>Constant numbers can't be used on last arithmetic instruction</td>
</tr>
<tr>
<td>ERROR_UNIKEY_AR_VALUE_OVERFLOW</td>
<td>221</td>
<td>Constant numbers > 63 will cause an overflow</td>
</tr>
</table>
 
 
----
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.
----
 
 
<table class="wikitable">
<tr>
<th>Internal Register</th>
<th>Description</th>
</tr>
<tr>
<td>E</td>
<td>Value in license module *lp2</td>
</tr>
<tr>
<td>F</td>
<td>Value in license module (*lp2 + 1)</td>
</tr>
<tr>
<td>G</td>
<td>Value in license module (*lp2 + 2)</td>
</tr>
<tr>
<td>H</td>
<td>Value in license module (*lp2 + 3)</td>
</tr>
</table>
 
 
----
Examples:
<br>When calling calculation 3 with *pModule = 0, the initial values of register E, F, G and H are:
<br>E = value of license module 0
<br>F = value of license module 1
<br>G = value of license module 2
<br>F = value of license module 3
<br>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:
<br>E = value of license module 126
<br>F = value of license module 127
<br>G = value of license module 0
<br>H = value of license module 1
----
 
 
----
<code>UniKey_Calculate</code> 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 <code>UniKey_Calculate</code> to perform the algorithm and get the return value of the formula.
----
 
<br>
 
=== Decrease a License Module ===
 
'''API Prototype'''
 
<code>long UniKey_Module_Decrease(WORD* pHandle, WORD* pModule);</code>
 
'''Description'''
 
Decrease the value in a specified UniKey license module by "1".
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>
 
 
----
Please call <code>UniKey_Check_Module</code> to check if the license module is valid first.
----
 
<br>
 
=== Generate a New Password ===
 
'''API Prototype'''
 
<code>long UniKey_Generate_New_Password(WORD* pHandle, DWORD* pSeed, WORD* pPassword1, WORD* pPassword2, WORD* pPassword3, WORD* pPassword4);</code>
 
'''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'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pSeed</td>
<td>[in] Seed code (32-bit)</td>
</tr>
<tr>
<td>*pPassword1</td>
<td>[out] New password 1</td>
</tr>
<tr>
<td>*pPassword2</td>
<td>[out] New password 2</td>
</tr>
<tr>
<td>*pPassword3</td>
<td>[out] New password 3</td>
</tr>
<tr>
<td>*pPassword4</td>
<td>[out] New password 4</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_VERIFY_ADV_PASSWORD</td>
<td>223</td>
<td>Advanced passwords (passwords 3 and 4) not verified</td>
</tr>
<tr>
<td>ERROR_UNIKEY_GENERATE_NEW_PASSWORD</td>
<td>225</td>
<td>Error generating new password</td>
</tr>
</table>
 
 
----
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.
----
 
<br>
 
=== Generate a New Encryption Key ===
 
'''API Prototype'''
 
<code>long UniKey_Generate_Key(WORD* pHandle, DWORD* pKeyNumber);</code>
 
'''Description'''
 
Generate a new key in the specific key storage.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pKeyNumber</td>
<td>[in] Key storage number</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_KEY_STORE</td>
<td>224</td>
<td>Wrong key storage number</td>
</tr>
</table>
 
 
----
# 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.
----
 
<br>
 
=== Generate a New Encryption Key via Seed ===
 
'''API Prototype'''
 
<code>long UniKey_Generate_Key_Via_Seed(WORD* pHandle, DWORD* pKeyNumber, WORD pSeed1, WORD pSeed2, WORD pSeed3, WORD pSeed4);</code>
 
'''Description'''
 
Generate a new key in the specific key storage via a seed.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pKeyNumber</td>
<td>[in] Key storage number</td>
</tr>
<tr>
<td>*pSeed1</td>
<td>[in] Seed 1</td>
</tr>
<tr>
<td>*pSeed2</td>
<td>[in] Seed 2</td>
</tr>
<tr>
<td>*pSeed3</td>
<td>[in] Seed 3</td>
</tr>
<tr>
<td>*pSeed4</td>
<td>[in] Seed 4</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_KEY_STORE</td>
<td>224</td>
<td>Wrong key storage number</td>
</tr>
</table>
 
 
----
# 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.
----
 
<br>
 
=== Encrypt the Buffer with a Specific Encryption Key ===
 
'''API Prototype'''
 
<code>long UniKey_Encrypt(WORD* pHandle, DWORD* pBufferLength, DWORD* pKeyNumber, BYTE* pBuffer);</code>
 
'''Description'''
 
Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pBufferLength</td>
<td>[in] Number of bytes to encrypt</td>
</tr>
<tr>
<td>*pKeyNumber</td>
<td>[in] Key storage number</td>
</tr>
<tr>
<td rowspan="2">*pBuffer</td>
<td>[in] Pointer to the data to be encrypted</td>
</tr>
<tr>
<td>[out] Pointer to the encrypted data</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_KEY_STORE</td>
<td>224</td>
<td>Wrong key storage number</td>
</tr>
<tr>
<td>ERROR_UNIKEY_ENCRYPT_FAILED</td>
<td>228</td>
<td>Could not encrypt data</td>
</tr>
</table>
 
 
----
This function only performs an encryption operation, no compression functions are involved.
----
 
<br>
 
=== Decrypt the Buffer with a Specific Encryption Key ===
 
'''API Prototype'''
 
<code>long UniKey_Decrypt(WORD* pHandle, DWORD* pBufferLength, DWORD* pKeyNumber, BYTE* pBuffer);</code>
 
'''Description'''
 
Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pBufferLength</td>
<td>[in] Number of bytes to encrypt</td>
</tr>
<tr>
<td>*pKeyNumber</td>
<td>[in] Key storage number</td>
</tr>
<tr>
<td rowspan="2">*pBuffer</td>
<td>[in] Pointer to the data to be decrypted</td>
</tr>
<tr>
<td>[out] Pointer to the decrypted data</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_KEY_STORE</td>
<td>224</td>
<td>Wrong key storage number</td>
</tr>
<tr>
<td>ERROR_UNIKEY_DECRYPT_FAILED</td>
<td>229</td>
<td>Could not decrypt data</td>
</tr>
</table>
 
 
----
Please use the key that was used to encrypt the data to decrypt the data, otherwise you cannot properly decrypt the data.
----
 
 
----
<code>UniKey_Encrypt</code> and <code>UniKey_Decrypt</code> 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.
----
 
<br>
 
=== Make an MD5 Digest for Certain Content  ===
 
'''API Prototype'''
 
<code>long UniKey_MD5(WORD* pHandle, DWORD* pBufferLength, DWORD* pType, BYTE* pBuffer);</code>
 
'''Description'''
 
Make an MD5 digest of content or data.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pBufferLength</td>
<td>[in] Number of bytes to MD5</td>
</tr>
<tr>
<td rowspan="2">*pBuffer</td>
<td>[in] Pointer to the data to be digested</td>
</tr>
<tr>
<td>[out] Pointer to the digested data</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
</table>
 
<br>
 
=== Read UpdateTag  ===
 
'''API Prototype'''
 
<code>long UniKey_Read_UpdateTag(WORD* pHandle, DWORD* pUpdateTag);</code>
 
'''Description'''
 
Read UpdateTag from a specific dongle
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pUpdateTag</td>
<td>[out] UpdateTag</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_READ_UPDATETAG</td>
<td>226</td>
<td>Read UpdateTag error</td>
</tr>
</table>
 
<br>
 
=== Write UpdateTag ===
 
'''API Prototype'''
 
<code>long UniKey_Write_UpdateTag(WORD* pHandle, DWORD* pUpdateTag);</code>
 
'''Description'''
 
Write UpdateTag into a specific dongle.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pUpdateTag</td>
<td>[in] UpdateTag</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_UPDATETAG</td>
<td>227</td>
<td>Write UpdateTag error</td>
</tr>
</table>


<br>---------------------------------------------------------------------------------------------------<br>A successful operation will result in the user-defined algorithm populated with the algorithm command string from the buffer. <br>--------------------------------------------------------------------------------------------------


----
----
<code>UniKey_Read_UpdateTag</code> 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.
----
<br>
=== Get UniKey Library Version ===
'''API Prototype'''
<code>long UniKey_Get_Version(WORD* pHandle, DWORD* pVersion);</code>
'''Description'''
Get the current UniKey library version.
'''Parameters'''
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pVersion</td>
<td>[out] UniKey library version</td>
</tr>
</table>
<br>
===Lock a UniKey Dongle===
'''API Prototype'''
<code>long UniKey_Lock(WORD *pHandle)</code>
'''Description'''
Create a mutex to lock the UniKey dongle.
'''Parameters'''
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_ALREADY_LOCKED</td>
<td>236</td>
<td>Dongle already locked (when attempting to lock twice, or open after locking a dongle)</td>
</tr>
</table>
<br>
===Unlock a UniKey Dongle===
'''API Prototype'''
<code>long UniKey_UnLock(WORD *pHandle)</code>
'''Description'''
Free the mutex to unlock the UniKey dongle.
'''Parameters'''
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[out] Dongle handle</td>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


<br>UniKey_Write_Arithmetic is called when you write a series of algorithms into the dongle. This function is only called at software vendor side. For example, if you have a serial number generate algorithm, and you want to perform this algorithm inside the dongle, you need to call UniKey_Write_Arithmetic. <br>--------------------------------------------------------------------------------------------------
<br>


== <br>User-defined Algorithm Calculate 1  ==
== UniKey Time API Reference ==


<br>'''API Prototype'''<br><code>long UniKey_Calculate1( WORD* pHandle , <br>DWORD* pStartAddress , <br>DWORD* pModule ,<br>WORD* pRegA , <br>WORD* pRegB , <br>WORD* pRegC ,<br>WORD* pRegD )&nbsp;;</code>
=== Get UniKey Time  ===


'''Description'''<br>Return the results of a calculation performed in UniKey, using input provided by the developer and the CALCULATE1 function.
'''API Prototype'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pStartAddress [in] Start point of calculation<br>*pModule [in] License module number<br>*p1 [in, out] Register A<br>*p2 [in, out] Register B<br>*p3 [in, out] Register C<br>*p4 [in, out] Register D
<code>long UniKey_Get_Time(WORD* pHandle, DWORD* pYear, DWORD* pMonth, WORD* pDay, WORD* pHour, WORD* pMinute, WORD* pSecond);</code>
 
'''Description'''
 
Get the time from the UniKey Time’s real-time clock.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pYear</td>
<td>[out] Year (input or output is 10, which refers to 2010)</td>
</tr>
<tr>
<td>*pMonth</td>
<td>[out] Month</td>
</tr>
<tr>
<td>*pDay</td>
<td>[out] Day</td>
</tr>
<tr>
<td>*pHour</td>
<td>[out] Hour</td>
</tr>
<tr>
<td>*pMinute</td>
<td>[out] Minute</td>
</tr>
<tr>
<td>*pSecond</td>
<td>[out] Second</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_READ_TIME</td>
<td>230</td>
<td>Get UniKey time error</td>
</tr>
</table>


Return value<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_AR_BAD_COMMAND 217 Arithmetic instruction Error<br>ERROR_UNIKEY_AR_UNKNOWN_OPCODE 218 Arithmetic operator Error<br>ERROR_UNIKEY_AR_WRON_GBEGIN 219 Const number can't use on first arithmetic instruction<br>ERROR_UNIKEY_AR_WRONG_END 220 Const number can't use on last arithmetic instruction<br>ERROR_UNIKEY_AR_VALUE_OVERFLOW 221 Const number &gt; 63


----
----
Calling <code>UniKey_Check_Time</code> 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.
----
<br>


<br>When the calculation starts, the values of other internal registers are listed in the table below. <br>E and F are reversed hardware ID byte wisely. For example, if the hardware is 0x12345678 (in Hex), and E will be 0x7856, and F will be 0x3412.<br>---------------------------------------------------------------------------------------------------<br>Internal Register Meaning<br>E HiWord of reversed hardware ID <br>F LoWord of reversed hardware ID <br>G Value stored in license module *pModule<br>H Random number <br>---------------------------------------------------------------------------------------------------<br>Examples <br>If the internal algorithm is A = B + C, <br>Then the call result is *p1 = *p2 + *p3. <br>For example: The internal algorithm is A = A + G; If *p1 = 0, then when returning you may guess the content of license module *p1 = *pModule. Though you cannot read the content of modules directly, you may determine the content by algorithm. If possible, you had better check the content with an algorithm, not only comparing it in the program. <br>---------------------------------------------------------------------------------------------------
=== Set UniKey Time  ===


== <br>User-defined Algorithm Calculate 2  ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Calculate2( WORD* pHandle ,<br>DWORD* pStartAddress ,<br>DWORD* pSeed ,<br>WORD* pRegA ,<br>WORD* pRegB , <br>WORD* pRegC , <br>WORD* pRegD )&nbsp;;</code>  
<code>long UniKey_Set_Time(WORD* pHandle, DWORD* pYear, DWORD* pMonth, WORD* pDay, WORD* pHour, WORD* pMinute, WORD* pSecond);</code>


'''Description'''<br>Return the results of a calculation performed in UniKey, using input provided by the developer and the CALCULATE2 function.
'''Description'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pStartAddress [in] Start point of calculation<br>*pSeed [in] Seed Code (32-bit)<br>*p1 [in, out] Register A<br>*p2 [in, out] Register B<br>*p3 [in, out] Register C<br>*p4 [in, out] Register D
Set the time on the UniKey Time’s clock.


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_AR_BAD_COMMAND 217 Arithmetic instruction Error<br>ERROR_UNIKEY_AR_UNKNOWN_OPCODE 218 Arithmetic operator Error<br>ERROR_UNIKEY_AR_WRON_GBEGIN 219 Const number can't use on first arithmetic instruction<br>ERROR_UNIKEY_AR_WRONG_END 220 Const number can't use on last arithmetic instruction<br>ERROR_UNIKEY_AR_VALUE_OVERFLOW 221 Const number &gt; 63
'''Parameters'''


<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pYear</td>
<td>[in] Year (input or output is 10, which refers to 2010)</td>
</tr>
<tr>
<td>*pMonth</td>
<td>[in] Month</td>
</tr>
<tr>
<td>*pDay</td>
<td>[in] Day</td>
</tr>
<tr>
<td>*pHour</td>
<td>[in] Hour</td>
</tr>
<tr>
<td>*pMinute</td>
<td>[in] Minute</td>
</tr>
<tr>
<td>*pSecond</td>
<td>[in] Second</td>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_READ_TIME</td>
<td>230</td>
<td>Get UniKey time error</td>
</tr>
</table>
----
You need to verify all 4 passwords (vendor mode) to set the time of the UniKey Time's internal clock.
----
----


<br>When performing calculation 2, the initial values of register E, F, G and H are the '''Return values''' of seed code *pSeed, to make it simple, UNIKEY calls function SEED with seed code *pSeed, and writes the '''Return values''' to register E, F, G and H for the next operation. <br>--------------------------------------------------------------------------------------------------


Internal Register Meaning<br>E Seed Result 1<br>F Seed Result 2<br>G Seed Result 3<br>H Seed Result 4
<br>
 
=== Set UniKey Time by Host’s Clock  ===
 
'''API Prototype'''
 
<code>long UniKey_Set_Time_Now(WORD* pHandle);</code>
 
'''Description'''
 
Set the time of the UniKey Time’s real-time clock to the host computer’s clock.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
</table>
 
<br>


&nbsp;
=== Erase Real Time Module  ===


== User-defined Algorithm Calculate 3  ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Calculate3( WORD* pHandle ,<br>DWORD* pStartAddress ,<br>DWORD* pModule , <br>WORD* pRegA , <br>WORD* pRegB , <br>WORD* pRegC , <br>WORD* pRegD )&nbsp;;</code>  
<code>long UniKey_Erase_Time_Module(WORD* pHandle, DWORD* pModule);</code>


'''Description''' <br>Return results of a calculation performed in UniKey, using input provided by the developer and the CALCULATE3 function.
'''Description'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pStartAddress [in] Start point of calculation<br>*pModule [in] License module number<br>*pRegA [in, out] Register A<br>*pRegB [in, out] Register B<br>*pRegC [in, out] Register C<br>*pRegD [in, out] Register D
Erase/Reset a real-time module, and all the information in the module will be erased including start, and end or duration.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Real-time module number (0-15)</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
</table>


Return value <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_AR_BAD_COMMAND 217 Arithmetic instruction Error<br>ERROR_UNIKEY_AR_UNKNOWN_OPCODE 218 Arithmetic operator Error<br>ERROR_UNIKEY_AR_WRON_GBEGIN 219 Const number can't use on first arithmetic instruction<br>ERROR_UNIKEY_AR_WRONG_END 220 Const number can't use on last arithmetic instruction<br>ERROR_UNIKEY_AR_VALUE_OVERFLOW 221 Const number &gt; 63


----
----
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.
----
<br>


<br>When performing calculation 3, the initial values of register E, F, G and H are the content of license module *lp2 and *lp2+1/2/3. <br>------------------------------------------------------------------------------------------------------
=== Set a Real Time Module’s Start Time ===


Internal Register Meaning<br>E Value in license module *lp2<br>F Value in license module (*lp2 + 1)<br>G Value in license module (*lp2 + 2)<br>H Value in license module (*lp2 + 3)<br>---------------------------------------------------------------------------------------------------<br>Examples<br>When calls calculation 3 with *pModule = 0, the initial values of register E, F, G and H are:<br>E = Value of license module 0<br>F = Value of license module 1<br>G = Value of license module 2<br>F = Value of license module 3<br>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:<br>E = Value of license module 126<br>F = Value of license module 127<br>G = Value of license module 0<br>H = Value of license module 1<br>---------------------------------------------------------------------------------------------------
'''API Prototype'''


<code>long UniKey_Set_Time_Module_Start_Time(WORD* pHandle, DWORD* pModule, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);</code>
'''Description'''
Set a real-time module’s start time.
'''Parameters'''
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Real-time module number (0-15)</td>
</tr>
<tr>
<td>*pYear</td>
<td>[in] Year (input or output is 10, which refers to 2010)</td>
</tr>
<tr>
<td>*pMonth</td>
<td>[in] Month</td>
</tr>
<tr>
<td>*pDay</td>
<td>[in] Day</td>
</tr>
<tr>
<td>*pHour</td>
<td>[in] Hour</td>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME_MODULE</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_TIME_MODULE_NOT_NULL</td>
<td>234</td>
<td>The real-time module is not null, this error is returned when the 'write once' flag is set</td>
</tr>
</table>
----
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.
----
----


<br>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 algorithms and get the return of the formula. <br>---------------------------------------------------------------------------------------------------
<br>


&nbsp;
=== Set a Real Time Module’s Start Time by the UniKey's Internal Clock  ===


== Decrease A License module ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Module_Decrease( WORD* pHandle ,<br>WORD* pModule ) ;</code>
<code>long UniKey_Set_Time_Module_Start_Time_Now(WORD* pHandle, DWORD* pModule);</code>


'''Description'''<br>Decrease the value in a specified UniKey license module by “1”.
'''Description'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module number
Set a real-time module’s start time as the current time in the UniKey's internal clock.


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 204 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error
'''Parameters'''


---------------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Real-time module number (0-15)</td>
</tr>
</table>


Please call UniKey_Check_Module to check if the license module is valid first.<br>---------------------------------------------------------------------------------------------------
'''Return values'''


== <br>Generate a New Password ==
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME_MODULE</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_TIME_MODULE_NOT_NULL</td>
<td>234</td>
<td>The real-time module is not null, this error is returned when the 'write once' flag is set</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long UniKey_Generate_New_Password( WORD* pHandle ,<br>DWORD* pSeed ,<br>WORD* pPassword1 , <br>WORD* pPassword2 , <br>WORD* pPassword3 , <br>WORD* pPassword4 ) ;</code>
<br>


'''Description'''<br>Generate a new password via a seed code; the mapping from the seed code to the password is only one way. Without the seed, you cannot generate the same password.
=== Set a Real Time Module’s Start Time by Host’s Clock ===


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pSeed [in] Seed Code (32-bit)<br>*pPassword1 [out] New password 1<br>*pPassword2 [out] New password 2<br>*pPassword3 [out] New password 3<br>*pPassword4 [out] New password 4
'''API Prototype'''


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_VERIFY_ADV_PASSWORD 223 Advanced passwords (password3 and passowrd4) not verified<br>ERROR_UNIKEY_GENERATE_NEW_PASSWORD 225 Generate new password Error
<code>long UniKey_Set_Time_Module_Start_Time_Now_PC(WORD* pHandle, DWORD* pModule);</code>


---------------------------------------------------------------------------------------------------<br>A file recording the new SEED and PASSWORDs will be created in the working path, and help the software vendor to recall everything. The passwords can be distributed to ordinary developers! <br>---------------------------------------------------------------------------------------------------
'''Description'''


---------------------------------------------------------------------------------------------------<br>1. The dongle will be automatically logoff after a new set of passwords are generated. <br>2. The dongle will be fully formatted when a new password is generated. <br>3. A file including new password and seed will be created in the working directory. <br>--------------------------------------------------------------------------------------------------
Set a real time module’s start time as the current time of the host computer.


== <br>Generate a New Encryption Key ==
'''Parameters'''


<br>'''API Prototype'''<br><code>long UniKey_Generate_Key( WORD* pHandle , <br>DWORD* pKeyNumber ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Real-time module number (0-15)</td>
</tr>
</table>


'''Description'''<br>Generate a new key in the specific key storage.
'''Return values'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pKeyNumber [in] Key Storage Number
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME_MODULE</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_TIME_MODULE_NOT_NULL</td>
<td>234</td>
<td>The real-time module is not null, this error is returned when the 'write once' flag is set</td>
</tr>
</table>


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_INVALID_KEY_STORE 224 Wrong key storage number
<br>


---------------------------------------------------------------------------------------------------<br>1. This function will delete the original key in the key storage, and generate a new key. <br>2. The data encrypted by the old key cannot be decrypted by the new key. <br>3. Each key is 128-bit long. <br>----------------------------------------------------------------------------------------------------
=== Set a Real Time Module’s End Time ===


== <br>Generate a New Encryption Key Via Seed ==
'''API Prototype'''


<br>'''API Prototype'''<br><code>long UniKey_Generate_Key_Via_Seed( WORD* pHandle , <br>DWORD* pKeyNumber , <br>WORD pSeed1 , <br>WORD pSeed2 , <br>WORD pSeed3 , <br>WORD pSeed4 ) ;</code>
<code>long UniKey_Set_Time_Module_End_Time(WORD* pHandle, DWORD* pModule, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);</code>


'''Description'''<br>Generate a new key in the specific key storage via seed.
'''Description'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pKeyNumber [in] Key Storage Number<br>*pSeed1 [in] Seed1<br>*pSeed2 [in] Seed2<br>*pSeed3 [in] Seed3<br>*pSeed4 [in] Seed4
Set a real-time module’s end time.


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_INVALID_KEY_STORE 224 Wrong key storage number
'''Parameters'''


<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pHandle </td>
<td>[in] Real-time module number (0-15)</td>
</tr>
<tr>
<td>*pYear</td>
<td>[in] Year (input or output is 10, which refers to 2010)</td>
</tr>
<tr>
<td>*pMonth</td>
<td>[in] Month</td>
</tr>
<tr>
<td>*pDay</td>
<td>[in] Day</td>
</tr>
<tr>
<td>*pHour</td>
<td>[in] Hour</td>
</tr>
</table>


'''Return values'''


--------------------------------------------------------------------------------------------<br>1. This function will delete the original key in the key storage, and generate a new key via seed. <br>2. The data encrypted by the old key cannot be decrypted by the new key. <br>3. Each key is 128-bit long. <br>--------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME_MODULE</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
</table>


&nbsp;
<br>


== Encrypt the Buffer with a Specific Encryption Key ==
=== Set a Real Time Module’s Duration ===


<br>'''API Prototype'''<br><code>long UniKey_Encrypt( WORD* pHandle ,<br>DWORD* pBufferLength ,<br>DWORD* pKeyNumber , <br>BYTE* pBuffer ) ;</code>
'''API Prototype'''


'''Description'''<br>Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
<code>long UniKey_Set_Time_Module_Duration(WORD* pHandle, DWORD* pModule, DWORD* pDay, WORD* pHour);</code>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pBufferLength [in] Number of bytes to encrypt<br>*pKeyNumber [in] Key Storage Number<br>*pBuffer [in] Pointer to the data to be encrypted<br>[out] Pointer to the encrypted data
'''Description'''


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_INVALID_KEY_STORE 224 Wrong key storage number<br>ERROR_UNIKEY_ENCRYPT_FAILED 228 Encrypt data error
Set the duration for a specific real-time module. The total duration is (*pDay) * 24 + (*pHour) in hours.


'''Parameters'''


<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] Real-time module number (0-15)</td>
</tr>
<tr>
<td>*pDay</td>
<td>[in] Number of days</td>
</tr>
<tr>
<td>*pHour</td>
<td>[in] Number of hours</td>
</tr>
</table>


<br>---------------------------------------------------------------------------------------------------
'''Return values'''


This function only performs an encryption operation, no compression functions are involved. <br>---------------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_WRITE_TIME_MODULE</td>
<td>231</td>
<td>Set UniKey time error</td>
</tr>
</table>


== <br>Decrypt the Buffer with a Specific Encryption Key ==


<br>'''API Prototype'''<br><code>long UniKey_Decrypt( WORD* pHandle , <br>DWORD* pBufferLength , <br>DWORD* pKeyNumber , <br>BYTE* pBuffer ) ;</code>
----
You need to verify all 4 passwords (vendor mode) to set the duration for a real-time module.
----


'''Description'''<br>Encrypt an amount of memory with a key. The length of data must be a multiple of 8.
<br>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pBufferLength [in] Number of bytes to encrypt<br>*pKeyNumber [in] Key Storage Number<br>*pBuffer [in] Pointer to the data to be decrypted<br>[out] Pointer to the decrypted data
=== Check a UniKey Time License module ===


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Not logon dongle before operating dongle<br>ERROR_UNIKEY_INVALID_KEY_STORE 224 Wrong key storage number<br>ERROR_UNIKEY_DECRYPT_FAILED 229 Decrypt data error
'''API Prototype'''


---------------------------------------------------------------------------------------------------
<code>long UniKey_Check_Time_Module(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);</code>


Please use the key that encrypted data to decrypt the data; otherwise you cannot decrypt the data. <br>---------------------------------------------------------------------------------------------------
'''Description'''


<br>---------------------------------------------------------------------------------------------------<br>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 the credential before saving it into the UniKey’s memory. <br>---------------------------------------------------------------------------------------------------
Read the attributes of a specific UniKey Time license module.


&nbsp;
'''Parameters'''


== Make an MD5 Digest for a Certain Content  ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module Number</td>
</tr>
<tr>
<td>*pRemainDays</td>
<td>[out] Days remaining</td>
</tr>
<tr>
<td>*pYear</td>
<td>[in] Year (input or output is 10, which refers to 2010)</td>
</tr>
<tr>
<td>*pMonth</td>
<td>[in] Month</td>
</tr>
<tr>
<td>*pDay</td>
<td>[in] Day</td>
</tr>
<tr>
<td>*pHour</td>
<td>[in] Hour</td>
</tr>
</table>


&nbsp;
'''Return values'''


'''API Prototype'''<br><code>long UniKey_MD5( WORD* pHandle , <br>DWORD* pBufferLength ,<br>DWORD* pType , <br>BYTE* pBuffer ) ;</code>
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>


'''Description'''<br>Make an MD5 digest for a mount of content or data.


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pBufferLength [in] Number of bytes to MD5<br>*pBuffer [in] Pointer to the data to be digested<br>[out] Pointer to the digested data
----
A successful operation will result in *pValue having value from the validity of a license module (1 = license module value is not zero).


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle
The value of a license module cannot be read out directly and it is invisible to end users.
----


&nbsp;
<br>


== Read UpdateTag  ==
=== Check a UniKey Time License Module Now ===


<br>'''API Prototype'''<br><code>long UniKey_Read_UpdateTag( WORD* pHandle ,<br>DWORD* pUpdateTag ) ;</code>
'''API Prototype'''


'''Description'''<br>Read UpdateTag from a specific dongle
<code>long UniKey_Check_Time_Module_Now(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pRemainHours);</code>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pUpdateTag [out] UpdateTag
'''Description'''


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_READ_UPDATETAG 226 Read UpdateTag error
Read the attributes of a specific UniKey Time license module Now.


&nbsp;
'''Parameters'''


== Write UpdateTag ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pRemainDays</td>
<td>[out] Days remaining</td>
</tr>
<tr>
<td>*pRemainHours</td>
<td>[out] Hours remaining</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long UniKey_Write_UpdateTag( WORD* pHandle , <br>DWORD* pUpdateTag ) ;</code>
'''Return values'''


'''Description'''<br>Write UpdateTag into a specific dongle.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pUpdateTag [in] UpdateTag


'''Return values''' <br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_WRITE_UPDATETAG 227 Write UpdateTag error
----
A successful operation will result in *pValue having value from the validity (1 = license module value is not zero).


<br>---------------------------------------------------------------------------------------------------<br>UniKey_Read_UpdateTag APIs give software vendors an easy method to identify if the UniKey dongle needs to be updated. When distributing the software, software vendors may use the UpdateTag as an ID which shows if the dongle needs to update or has been updated. You can also use this Tag as a tracking ID for each update. <br>----------------------------------------------------------------------------------------------------
The value of a license module cannot be read out directly and it is invisible to end users.
----


== <br>Get UniKey Library Version ==
<br>


&nbsp;
=== Check a UniKey Time License Module Now PC ===


'''API Prototype'''<br><code>long UniKey_Get_Version( WORD* pHandle ,<br>DWORD* pVersion ) ;</code>
'''API Prototype'''


'''Description''' <br>Get the current UniKey library version.
<code>long UniKey_Check_Time_Module_Now_PC(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pRemainHours);</code>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pVersion [out] UniKey library version<br>
'''Description'''


Read the attributes of a specific UniKey Time license module Now PC.


'''Parameters'''


== Get UniKey Time  ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Dongle handle</td>
</tr>
<tr>
<td>*pModule</td>
<td>[in] License module number</td>
</tr>
<tr>
<td>*pRemainDays</td>
<td>[out] Days remaining</td>
</tr>
<tr>
<td>*pRemainHours</td>
<td>[out] Hours remaining</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long UniKey_Get_Time( WORD* pHandle , <br>DWORD* pYear ,<br>DWORD* pMonth ,<br>WORD* pDay , <br>WORD* pHour , <br>WORD* pMinute ,<br>WORD* pSecond ) ;</code>
'''Return values'''


'''Description''' <br>Get UniKey Time’s real time clock’s time.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE</td>
<td>204</td>
<td>Read/Write address is incorrect or invalid length</td>
</tr>
<tr>
<td>ERROR_UNIKEY_NEED_OPEN</td>
<td>212</td>
<td>Need to log on to a dongle before running</td>
</tr>
<tr>
<td>ERROR_UNIKEY_MODULE</td>
<td>216</td>
<td>License module error</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pYear [out] Year(input or output is 10, which refers to 2010)<br>*pMonth [out] Month<br>*pDay [out] Day<br>*pHour [out] Hour<br>*pMinute [out] Minute<br>*pSecond [out] Second


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_READ_TIME 230 Get UniKey time error
----
A successful operation will result in *pValue having value from the validity (1 = license module value is not zero).


---------------------------------------------------------------------------------------------------<br>We can call UniKey_Check_Time to check if the UniKey dongle is a real time dongle. If we get ERROR_UNIKEY_READ_TIME, then the dongle is not a real time dongle. <br>---------------------------------------------------------------------------------------------------
The value of a license module cannot be read out directly and it is invisible to end users.
----


== <br>Set UniKey Time  ==
<br>


<br>'''API Prototype'''<br><code>long UniKey_Set_Time( WORD* pHandle ,<br>DWORD* pYear , <br>DWORD* pMonth , <br>WORD* pDay , <br>WORD* pHour , <br>WORD* pMinute , <br>WORD* pSecond ) ;</code>
== UniKey Drive API Reference ==


'''Description''' <br>Set UniKey Time’s real time clock’s time.
=== Initialize File System ===


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pYear [in] Year (input or output is 10, which refers to 2010)<br>*pMonth [in] Month<br>*pDay [in] Day<br>*pHour [in] Hour<br>*pMinute [in] Minute<br>*pSecond [in] Second
'''API Prototype'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_READ_TIME 230 Get UniKey time error<br>---------------------------------------------------------------------------------------------------
<code>long UniKey_FS_Init(WORD* pHandle, DWORD* PW1, DWORD* PW2, DWORD* PW3, DWORD* PW4);</code>


You need verify all the 4 passwords (vendor mode) to set the time for UniKey internal clock. <br>-------------------------------------------------------------------------------------------------
'''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'''


== Set UniKey Time by Host’s Clock  ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*PW1</td>
<td>[in] Password 1</td>
</tr>
<tr>
<td>*PW2</td>
<td>[in] Password 2</td>
</tr>
<tr>
<td>*PW3</td>
<td>[in] Password 3</td>
</tr>
<tr>
<td>*PW4</td>
<td>[in] Password 4</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long UniKey_Set_Time_Now( WORD* pHandle ) ;</code>
'''Return values'''


'''Description''' <br>Set UniKey Time’s real time clock’s time by the host computer’s clock.<br><br>'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID</td>
<td>202</td>
<td>Wrong password or UniKey HID</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME 231 Write UniKey time error
<br>


=== Format the File System ===


'''API Prototype'''


== Erase Real Time Module  ==
<code>long UniKey_FS_Format(WORD* pHandle);</code>


<br>'''API Prototype'''<br><code>long UniKey_Erase_Time_Module( WORD* pHandle ,<br>DWORD* pModule ) ;</code>
'''Description'''


'''Description''' <br>Erase/Reset a real time module, and all the info in the module will be erased including start, end or duration.
Format the file system.


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] Real time module number (0-15)
'''Parameters'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME 231 Write UniKey time error
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
</table>


'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_FILE_EXIST</td>
<td>245</td>
<td>File already exists</td>
</tr>
</table>


---------------------------------------------------------------------------------------------------<br>You need verify all the 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. Later START_TIME call will return an error until this module is reset. <br>---------------------------------------------------------------------------------------------------<br>


----
Note: The user needs to initialize the file system successfully before calling other file system related functions.
----


<br>


== Set a Real Time Module’s Start Time ==
=== Create Files ===


<br>'''API Prototype'''<br><code>long UniKey_Set_Time_Module_Start_Time( WORD* pHandle , <br>DWORD* pModule , <br>WORD* pYear , <br>WORD* pMonth , <br>WORD* pDay , <br>WORD* pHour ) ;</code>
'''API Prototype'''


'''Description''' <br>Set a real time module’s start time.
<code>long UniKey_FS_CreateFile(WORD* pHandle, BYTE* filename);</code>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] Real time module number (0-15)<br>*pYear [in] Year(input or output is 10, which refers to 2010)<br>*pMonth [in] Month<br>*pDay [in] Day<br>*pHour [in] Hour
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME_MODULE 231 Write time module error<br>ERROR_UNIKEY_TIME_MODULE_NOT_NULL 234 The real time module is not null, this error is returned when write once flag is set
Create files.


---------------------------------------------------------------------------------------------------<br>Write Once flag is very useful for setting the Start for a real time module. If write once flag is set, only the first START_TIME call can set the start time for a module. All the later START_TIME 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. <br>---------------------------------------------------------------------------------------------------<br>
'''Parameters'''


&nbsp;
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filename</td>
<td>[in/out] Input/Output file name</td>
</tr>
</table>


== Set a Real Time Module’s Start Time by UniKey Dongle’s Clock  ==


<br>'''API Prototype'''<br><code>Long UniKey_Set_Time_Module_Start_Time_Now( WORD* pHandle ,<br>DWORD* pModule);</code>
----
Note: a single backslash ("\") should be added before the name of the file.
----


'''Description''' <br>Set a real time module’s start time as the now time in UniKey dongle’s clock.


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] Real time module number (0-15)
'''Return values'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME_MODULE 231 Write time module error<br>ERROR_UNIKEY_TIME_MODULE_NOT_NULL 234 The real time module is not null, this error is returned when write once flag is set
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_FILE_NAME</td>
<td>240</td>
<td>Wrong or invalid filename</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_FILE_EXIST</td>
<td>245</td>
<td>File already exists</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_ERR_SYS_UNINIT</td>
<td>246</td>
<td>The file system is not initialized</td>
</tr>
</table>


&nbsp;
<br>


== Set a Real Time Module’s Start Time by Host’s Clock ==
=== Delete Files ===


<br>'''API Prototype'''<br><code>long UniKey_Set_Time_Module_Start_Time_Now_PC( <br>WORD* pHandle , <br>DWORD* pModule ) ;</code>
'''API Prototype'''


'''Description''' <br>Set a real time module’s start time as the now time in host computer.
<code>long UniKey_FS_DeleteFile(WORD* pHandle, BYTE* filename);</code>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pHandle [in] Real time module number (0-15)
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME_MODULE 231 Write time module error<br>ERROR_UNIKEY_TIME_MODULE_NOT_NULL 234 The real time module is not null, this error is returned when write once flag is set
Delete files.


&nbsp;
'''Parameters'''


== Set a Real Time Module’s End Time ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filename</td>
<td>[in/out] Input/Output file name</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long UniKey_Set_Time_Module_End_Time( WORD* pHandle , <br>DWORD* pModule ,<br>WORD* pYear , <br>WORD* pMonth , <br>WORD* pDay , <br>WORD* pHour ) ;</code>
'''Return values'''


'''Description''' <br>Set a real time module’s end time.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_NO_FILE</td>
<td>241</td>
<td>No such filename</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_ERR_SYS_UNINIT</td>
<td>246</td>
<td>The file system is not initialized</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pHandle [in] Real time module number (0-15)<br>*pYear [in] Year(input or output is 10, which refers to 2010)<br>*pMonth [in] Month<br>*pDay [in] Day<br>*pHour [in] Hour
<br>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME_MODULE 231 Write time module error
=== Open Files ===


&nbsp;
'''API Prototype'''


== Set a Real Time Module’s Duration ==
<code>long UniKey_FS_File_Open(WORD* pHandle, BYTE* filename);</code>


<br>'''API Prototype'''<br><code>long UniKey_Set_Time_Module_Duration( WORD* pHandle , <br>DWORD* pModule ,<br>DWORD* pDay , <br>WORD* pHour ) ;</code>
'''Description'''


'''Description''' <br>Set the duration time for a specific real time module. The total duration is (*pDay)*24 + (*pHour) in hours.
Open files.  


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] Real time module number (0-15)<br>*pDay [in] Number of days<br>*pHour [in] Number of hours
'''Parameters'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_NEED_OPEN 212 Need open dongle before operating dongle<br>ERROR_UNIKEY_WRITE_TIME_MODULE 231 Write time module error
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filename</td>
<td>[in] Input/Output file name</td>
</tr>
</table>
 
'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_NO_FILE</td>
<td>241</td>
<td>No such filename</td>
</tr>
</table>


<br>


---------------------------------------------------------------------------------------------------
=== Get System Space ===


You need verify all the 4 passwords (vendor mode) to set the duration for a real time module.<br>-----------------------------------------------------------------------------------------------------
'''API Prototype'''


&nbsp;
<code>long UniKey_FS_Get_Free_Size(WORD* pHandle, DWORD* usedsize, DWORD* freesize);</code>


== Check a UniKey Time License module ==
'''Description'''


<br>'''API Prototype'''<br><code>long UniKey_Check_Time_Module( WORD* pHandle ,<br>DWORD* pModule ,<br>DWORD* pRemainDays ,<br>WORD* pYear ,<br>WORD* pMonth ,<br>WORD* pDay , <br>WORD* pHour ) ;</code>
Get occupied and free system space.


'''Description'''<br>Read the attributes of a specific UniKey Time license module.
'''Parameters'''


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module Number<br>*pRemainDays [out] Remain days<br>*pYear [in] Year (input or output is 10 ,which refers to 2010)<br>*pMonth [in] Month<br>*pDay [in] Day<br>*pHour [in] Hour
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*usedsize</td>
<td>[out] System memory that is in use</td>
</tr>
<tr>
<td>*freesize</td>
<td>[out] Free system memory</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error
'''Return values'''


---------------------------------------------------------------------------------------------------<br>A successful operation will result in “*pValue” with value from the Validity (1 = license module value is not zero). <br>The value of a license module cannot be read out directly and it is invisible to end users. <br>---------------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


&nbsp;
<br>


== Check a UniKey Time License module Now ==
=== Modify File Data ===


<br>'''API Prototype'''<br><code>long UniKey_Check_Time_Module_Now( WORD* pHandle ,<br>DWORD* pModule ,<br>DWORD* pRemainDays ,<br>WORD* pRemainHours ) ;</code>
'''API Prototype'''


<br>'''Description'''<br>Read the attributes of a specific UniKey Time license module now.
<code>long UniKey_FS_File_Modify_Data(WORD* pHandle, DWORD* offset, DWORD* len, BYTE* buffer);</code>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module Number<br>*pRemainDays [out] Remain days<br>*pRemainHours [out] Remain hours
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error
Modify file data.


---------------------------------------------------------------------------------------------------<br>A successful operation will result in “*pValue” with value from the Validity (1 = license module value is not zero).
'''Parameters'''


The value of a license module cannot be read out directly and it is invisible to end users. <br>---------------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*offset</td>
<td>[in] Address to be modified</td>
</tr>
<tr>
<td>*len</td>
<td>[in] Length of data to be modified</td>
</tr>
<tr>
<td>*buffer</td>
<td>[in] Modified data</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_FILE_OFFSET</td>
<td>242</td>
<td>File offset error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_ERR_OPEN_FILE</td>
<td>247</td>
<td>Failed to open file</td>
</tr>
</table>
 
<br>
 
=== Append Data to the End-Of-File ===
 
'''API Prototype'''
 
<code>long UniKey_FS_File_Append_Data(WORD* pHandle, DWORD* len, BYTE* buffer);</code>
 
'''Description'''
 
Append data to the end-of-file.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
</tr>
<tr>
<td>*len</td>
<td>[in] The length of the data to be appended</td>
</tr>
<tr>
<td>*buffer</td>
<td>[in] Data to append</td>
</tr>
</table>
 
'''Return values'''
 
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Meaning</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_NO_MEMORY</td>
<td>244</td>
<td>Not enough free memory</td>
</tr>
</table>
 
<br>
 
=== Read File Data ===
 
'''API Prototype'''
 
<code>long UniKey_FS_File_Read_Data(WORD* pHandle, DWORD* offset, DWORD* len, BYTE* buffer);</code>
 
'''Description'''
 
Read file data.
 
'''Parameters'''
 
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*offset</td>
<td>[in] Read address</td>
</tr>
<tr>
<td>*len</td>
<td>[in] Length of data to be read</td>
</tr>
<tr>
<td>*buffer</td>
<td>[out] Read data</td>
</tr>
</table>


== <br>Check a UniKey Time License module Now PC ==
'''Return values'''


<br>'''API Prototype'''<br><code>long UniKey_Check_Time_Module_Now_PC( WORD* pHandle ,<br>DWORD* pModule ,<br>DWORD* pRemainDays ,<br>WORD* pRemainHours) ;</code>
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_FILE_OFFSET</td>
<td>242</td>
<td>File offset error</td>
</tr>
<tr>
<td>ERROR_UNIKEY_FS_ERR_OPEN_FILE</td>
<td>247</td>
<td>Failed to open file</td>
</tr>
</table>


'''Description'''<br>Read the attributes of a specific UniKey Time license module Now PC.
<br>


'''Parameters''' <br>Parameter Meaning<br>*pHandle [in] Dongle handle<br>*pModule [in] License module Number<br>*pRemainDays [out] Remain days<br>*pRemainHours [out] Remain hours
=== Close Files ===


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_ADDR_OR_SIZE 202 Read/Write address or length is wrong<br>ERROR_UNIKEY_NEED_OPEN 212 No logon dongle before operating dongle<br>ERROR_UNIKEY_MODULE 216 License module error
'''API Prototype'''


---------------------------------------------------------------------------------------------------<br>A successful operation will result in “*pValue” with value from the Validity (1 = license module value is not zero).
<code>long UniKey_FS_File_Close(WORD* pHandle, BYTE* filename);</code>


The value of a license module cannot be read out directly and it is invisible to end users. <br>----------------------------------------------------------------------------------------------------<br>
'''Description'''


&nbsp;
Close files.


== Initialize File System ==
'''Parameters'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_Init( WORD* handle ,<br>DWORD* PW1 ,<br>DWORD* PW2 ,<br>DWORD* PW3 ,<br>DWORD* PW4 ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filename</td>
<td>[in] Filename</td>
</tr>
</table>


'''Description'''<br>The user needs to call this function to initialize the file system before calling other file system related functions. The password of the file system is 12345678.
'''Return values'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>* pPassword1 [in]Password1<br>* pPassword2 [in]Password2<br>* pPassword3 [in]Password3<br>* pPassword4 [in]Password4
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID 202 Invalid password or ID results in an error.
<br>


=== Get File List ===


'''API Prototype'''


== Format the file system ==
<code>long UniKey_FS_File_Get_List(WORD* pHandle, DWORD* filecount, BYTE* filelist);</code>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_Format( WORD* handle ) ;</code>
'''Description'''


'''Description'''<br>Format the file system.
Get list of files on the UniKey Drive.


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle
'''Parameters'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_FILE_EXIST 245 File already existed.
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filecount</td>
<td>[out] The number of files</td>
</tr>
<tr>
<td>*filelist</td>
<td>[out] File list</td>
</tr>
</table>


---------------------------------------------------------------------------------------------------
'''Return values'''


Note: The user needs to initialize the file system successfully before calling other file system related functions. <br>---------------------------------------------------------------------------------------------------
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


== <br>Create files ==
<br>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_CreateFile( WORD* handle ,<br>BYTE* filename ) ;</code>
=== Get File Size ===


'''Description'''<br>Create files.
'''API Prototype'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filename [in/out]Input/Output file name<br>---------------------------------------------------------------------------------------------------
<code>long UniKey_FS_File_Get_Size(WORD* pHandle, DWORD* filesize);</code>


Note: single slash ( "\") should be added before the name of the file.<br>---------------------------------------------------------------------------------------------------
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_ERR_SYS_UNINIT 246 The file system is not initialized.<br>ERROR_UNIKEY_FS_FILE_NAME 240 Wrong or invalid file name<br>ERROR_UNIKEY_FS_FILE_EXIST 245 The file already existed.
Get the file size.


'''Parameters'''


<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*filesize</td>
<td>[out] The size of the file</td>
</tr>
</table>


== Delete files ==
'''Return values'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_DeleteFile( WORD* handle , <br>BYTE* filename ) ;</code>
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


'''Description'''<br>Delete files.
<br>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filename [in/out]Input/Output file name
=== User Reset File System Password ===


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_ERR_SYS_UNINIT 246 The file is not yet initialized.<br>ERROR_UNIKEY_FS_NO_FILE 241 No such file name.
'''API Prototype'''


<code>long UniKey_FS_Set_Password(WORD* pHandle, DWORD* PW1, DWORD* PW2, DWORD* PW3, DWORD* PW4);</code>


'''Description'''


== Open files ==
Allows a user to reset the file system password.


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Open( WORD* handle ,<br>BYTE* filename ) ;</code>
'''Parameters'''


'''Description'''<br>Open files.
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*PW1</td>
<td>[in] Password 1</td>
</tr>
<tr>
<td>*PW2</td>
<td>[in] Password 2</td>
</tr>
<tr>
<td>*PW3</td>
<td>[in] Password 3</td>
</tr>
<tr>
<td>*PW4</td>
<td>[in] Password 4</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filename [in]Input/Output file name
'''Return values'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_NO_FILE 241 No such file name
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_GENERATE_NEW_PASSWORD</td>
<td>225</td>
<td>Error generating new password</td>
</tr>
</table>




----
A password reset can only be successfully done after initializing the file system.
----


== Get system space ==
<br>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_Get_Free_Size( WORD* handle , <br>DWORD* usedsize ,<br>DWORD* freesize ) ;</code>
=== Generate RSA Key ===


'''Description'''<br>Get system space.
'''API Prototype'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*usedsize [out]System space size which has already been used<br>*freesize [out]System space size that hasn’t been used
<code>long UniKey_RSA_Generate_Key(WORD* pHandle, WORD* KeyIndex);</code>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success
'''Description'''


UniKey Drive has encryption and decryption modules with 1024-bit RSA keys. Calling this function can generate a 1024-bit RSA key.


'''Parameters'''


== Modify file data ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[out] Return the handle generated key</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Modify_Data( <br>WORD* handle , <br>DWORD* offset ,<br>DWORD* len ,<br>BYTE* buffer ) ;</code>
'''Return values'''


<br>'''Description'''<br>Modify file data.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*offset [in]Address to be modified<br>*len [in]Modify the data length<br>*buffer [in]Modify the data
<br>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_ERR_OPEN_FILE 247 The file to be modified hasn’t been opened yet.<br>ERROR_UNIKEY_FS_FILE_OFFSET 242 Offset of file error
=== Generate a DES Key ===


'''API Prototype'''


<code>long UniKey_DES_Generate_Key(WORD* pHandle, DWORD* KeyIndex);</code>


== Append data to the end-of-file ==
'''Description'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Append_Data( WORD* handle ,<br>DWORD* len ,<br>BYTE* buffer ) ;</code>
Calling this function can generate a DES key.


'''Description'''<br>Append data to the end-of-file.
'''Parameters'''


'''Parameters'''<br>Parameter Meaning<br>*len [in]The length of the append data<br>*buffer [in]Append data
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[out] Return the handle generated key</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_NO_MEMORY 244 Not enough free memory
'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid</td>
</tr>
</table>


<br>


== Read file data ==
=== RSA Get Number of Generated Keys  ===


<br>'''API Prototype'''<br><code>long__stdcall UniKey_FS_File_Read_Data( WORD* handle ,<br>DWORD * offset ,<br>DWORD* len ,<br>BYTE* buffer ) ;</code>
'''API Prototype'''


'''Description'''<br>Read data file.
<code>long UniKey_RSA_Get_Key_Counts(WORD* pHandle, DWORD* KeyIndexs);</code>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*offset [in]Read address<br>*len [in]Read the data length<br>*buffer [out]Read data
'''Description'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_FS_ERR_OPEN_FILE 247 The file to be modified is not opened yet.<br>ERROR_UNIKEY_FS_FILE_OFFSET 242 Offset of file error.
Get the number of RSA keys that are generated.


== <br>Close files ==
'''Parameters'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Close( WORD* handle , <br>BYTE* filename ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[out] Key count</td>
</tr>
</table>


'''Description'''<br>Close files.
'''Return values'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filename [in]file name<br>*len [in]Read the data length<br>*buffer [in]Read data
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success
<br>


=== DES Get Number of Generated Keys ===


'''API Prototype'''


== Get file list ==
<code>long UniKey_DES_Get_Key_Counts(WORD* pHandle, DWORD* KeyIndexs);</code>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Get_List( WORD* handle ,<br>DWORD* filecount ,<br>BYTE* filelist ) ;</code>
'''Description'''


'''Description'''<br>Get file list.
Get the number of DES keys that are generated.


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filecount [out]The number of files<br>*filelist [out]
'''Parameters'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[out] Key count</td>
</tr>
</table>


'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid</td>
</tr>
</table>


== Get the file size ==
<br>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_File_Get_Size(WORD* handle, <br>DWORD* filesize);</code>
=== RSA Encryption  ===


<br>'''Description'''<br>Get the file size.
'''API Prototype'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*filesize [out]The size of the file
<code>long UniKey_RSA_Encrypt(WORD* pHandle, WORD* KeyIndex, DWORD* Encrypt_Len, BYTE* Buffer);</code>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success
'''Description'''


Encrypt data using RSA.


'''Parameters'''


== Users reset file system password ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] Encrypt and decrypt using the key handle</td>
</tr>
<tr>
<td>*Encrypt_Len</td>
<td>[in] Data length to be encrypted</td>
</tr>
<tr>
<td>*Buffer</td>
<td>[in/out] Input plain text and output encrypted text</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_FS_Set_Password( WORD* handle ,<br>DWORD* PW1 ,<br>DWORD* PW2 ,<br>DWORD* PW3 ,<br>DWORD* PW4 ) ;</code>
'''Return values'''


'''Description'''<br>Users reset the password to the file system.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_ENCRYPT_FAILED</td>
<td>228</td>
<td>Could not encrypt data</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*pPassword1 [in]Password 1<br>*pPassword2 [in]Password 2<br>*pPassword3 [in]Password 3<br>*pPassword4 [in]Password 4
<br>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_GENERATE_NEW_PASSWORD 225 Fail to generate new password.<br><br>---------------------------------------------------------------------------------------------------
=== RSA Decryption  ===


The reset of the password can only be successfully done after initializing the file system successfully.<br>-----------------------------------------------------------------------------------------------------
'''API Prototype'''


<code>long UniKey_RSA_Decrypt(WORD* pHandle, WORD* KeyIndex, DWORD* Decrypt_Len, BYTE* Buffer);</code>


'''Description'''


== Generate a RSA Key ==
Decrypt data using RSA.


<br>'''API Prototype'''<br><code>long __stdcall UniKey_RSA_Generate_Key( WORD* handle ,<br>WORD* KeyIndex ) ;</code>
'''Parameters'''


'''Description'''<br>UniKey Drive has encryption &amp; decryption modules with 1024-bit RSA keys. <br>Calling this function can generate a 1024-bit RSA key.
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in]Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] Encrypt and decrypt using the key handle</td>
</tr>
<tr>
<td>*Decrypt_Len</td>
<td>[in] Length of data to be decrypted</td>
</tr>
<tr>
<td>*Buffer</td>
<td>[in/out] Input encrypted text and output plain text.</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*KeyIndex [in]Return the handle generated Key<br>` <br>'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The handle of the key is invalid.
'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_DECRYPT_FAILED</td>
<td>229</td>
<td>Could not decrypt data</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The key handle is invalid</td>
</tr>
</table>


<br>


== Generate a DES Key ==
=== DES Encryption  ===


<br>'''API Prototype'''<br><code>long __stdcall UniKey_DES_Generate_Key( WORD* handle ,<br>DWORD* KeyIndex ) ;</code>
'''API Prototype'''


'''Description'''<br>Calling this function can generate a DES key.
<code>
long UniKey_DES1_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*KeyIndex [in]Return the handle generated Key
long UniKey_DES2_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The handle of the key is invalid.
long UniKey_DES3_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);
</code>


'''Description'''


Encrypt data using DES.


== RSA Get key counts generated  ==
'''Parameters'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_RSA_Get_Key_Counts( WORD* handle ,<br>DWORD* KeyIndexs ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<tr>
<td>*EncryptMode</td>
<td>[in] Block cipher mode of operation</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] Encrypt and decrypt using the key handle</td>
</tr>
<tr>
<td>*Len</td>
<td>[in] Length of data to be encrypted</td>
</tr>
<tr>
<td>*Buffer</td>
<td>[in/out] Input plain text and output encrypted text.</td>
</tr>
</table>


'''Description'''<br>Get the number of keys that are generated.
'''Return values'''


'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [out]The key counts returned
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_ENCRYPT_FAILED</td>
<td>228</td>
<td>Could not encrypt data</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The key handle is invalid</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The handle of the key is invalid.
<br>


DES Get key counts generated <br>'''API Prototype'''<br><code>long __stdcall UniKey_DES_Get_Key_Counts( WORD* handle ,<br>DWORD* KeyIndexs ) ;</code>
=== DES Decryption  ===


'''Description'''<br>Get the number of keys that are generated.
'''API Prototype'''


<br>'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [out]The key counts returned
<code>
long UniKey_DES1_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The handle of the key is invalid.
long UniKey_DES2_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);


long UniKey_DES3_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);
</code>


'''Description'''


== RSA encryption  ==
Encrypt data using DES.


<br>'''API Prototype'''<br><code>long __stdcall UniKey_RSA_Encrypt( WORD* handle ,<br>WORD* KeyIndex ,<br>DWORD* Encrypt_Len ,<br>BYTE* Buffer ) ;</code>
'''Parameters'''


'''Description'''<br>Encrypt data using RSA.
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<tr>
<td>*DecryptMode</td>
<td>[in] Block cipher mode of operation</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] Encrypt and decrypt using the key handle</td>
</tr>
<tr>
<td>*Len</td>
<td>[in] Length of data to be decrypted</td>
</tr>
<tr>
<td>*Buffer</td>
<td>[in/out] Input encrypted text and output plain text.</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [in]Encrypt &amp; decrypt using the key handle<br>*Len [in]The length of encryption &amp; decryption data<br>*Buffer [in/out]Input encrypted text and output plain text.
'''Return values'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_ENCRYPT_FAILED 228 Encryption failed.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_DECRYPT_FAILED</td>
<td>229</td>
<td>Could not decrypt data</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The key handle is invalid</td>
</tr>
</table>


== <br>RSA decryption  ==
<br>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_RSA_Decrypt( WORD* handle ,<br>WORD* KeyIndex ,<br>DWORD* Decrypt_Len ,<br>BYTE* Buffer ) ;</code>
=== Delete RSA Key  ===


'''Description'''<br>Decrypt data using RSA.
'''API Prototype'''


'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [in]Encrypt &amp; decrypt using the key handle<br>*Len [in]The length of encryption &amp; decryption data<br>*Buffer [in/out]Input encrypted text and output plain text.
<code>long UniKey_RSA_Del_Key(WORD* pHandle, WORD* KeyIndex);</code>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid. <br>ERROR_UNIKEY_DECRYPT_FAILED 229 Decryption failed.
'''Description'''


== <br>DES encryption  ==
Delete a RSA key.


<br>'''API Prototype'''<br><code>long __stdcall UniKey_DES1_Encrypt( WORD* handle ,<br>WORD* EncryptMode ,<br>WORD* KeyIndex ,<br>DWORD* Len ,<br>BYTE* Buffer ) ;</code>
'''Parameters'''


long __stdcall UniKey_DES2_Encrypt( <br>WORD* handle ,<br>WORD* EncryptMode ,<br>WORD* KeyIndex ,<br>DWORD* Len ,<br>BYTE* Buffer ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] The handle to be deleted</td>
</tr>
</table>


long __stdcall UniKey_DES3_Encrypt( WORD* handle ,<br>WORD* EncryptMode ,<br>WORD* KeyIndex ,<br>DWORD* Len ,<br>BYTE* Buffer ) ;</code>
'''Return values'''


'''Description'''<br>Encrypt data using DES.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Meaning</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid<br>0 > KeyIndex > 3</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [in]Encrypt &amp; decrypt using the key handle<br>*Len [in]The length of encryption &amp; decryption data<br>*Buffer [in/out]Input encrypted text and output plain text.
<br>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid. <br>ERROR_UNIKEY_ENCRYPT_FAILED 228 Encryption failed.
=== Delete DES Key ===


'''API Prototype'''


<code>long UniKey_DES_Del_Key(WORD* pHandle, WORD* KeyIndex);</code>


== DES decryption  ==
'''Description'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_DES1_Decrypt( <br>WORD* handle ,<br>WORD* DecryptMode ,<br>WORD* KeyIndex ,<br>DWORD *Len ,<br>BYTE* Buffer ) ;</code>
Delete a DES key.


long __stdcall UniKey_DES2_Decrypt( WORD* handle ,<br>WORD* DecryptMode ,<br>WORD* KeyIndex ,<br>DWORD* Len ,<br>BYTE* Buffer ) ;</code>
'''Parameters'''


long __stdcall UniKey_DES3_Decrypt( WORD* handle ,<br>WORD* DecryptMode ,<br>WORD* KeyIndex ,<br>DWORD* Len ,<br>BYTE* Buffer ) ;</code>
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*KeyIndex</td>
<td>[in] Key handle to be deleted</td>
</tr>
</table>


'''Description'''<br>Encrypt data using DES.
'''Return values'''


'''Parameters'''<br>Parameter Meaning<br>*Phandle [in]Device handle<br>*KeyIndex [in]Encrypt &amp; decrypt using the key handle<br>*Len [in]The length of encryption &amp; decryption data<br>*Buffer [in/out]Input encrypted text and output plain text.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_KEY_INDEX</td>
<td>239</td>
<td>The handle of the key is invalid<br>0 > KeyIndex > 14</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid. <br>ERROR_UNIKEY_DECRYPT_FAILED 229 Decryption failed.
<br>


=== Get User Counts ===


'''API Prototype'''


== Delete key 1  ==
<code>long UniKey_Get_UserCount(WORD* pHandle, WORD* Count);</code>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_RSA_Del_Key( WORD* handle ,<br>WORD* KeyIndex ) ;</code>
'''Description'''


'''Description'''<br>Delete a key.
UniKey Drive can enable 32 concurrent users to log in. This function can be called to get the number of users logged in.


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*KeyIndex [in]The handle to be deleted
'''Parameters'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid.<br>KeyIndex &lt;0 or KeyIndex &gt; 3.
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*Count </td>
<td>[out] Number of users logged in</td>
</tr>
</table>


'''Return values'''


<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


== Delete key 2 ==
<br>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_DES_Del_Key( WORD* handle ,<br>WORD* KeyIndex ) ;</code>
=== Only Allow One User to Log in ===


'''Description'''<br>Delete a key.
'''API Prototype'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*KeyIndex [in]The handle to be deleted
<code>long UniKey_Logon_Single(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2, DWORD* pPassword3, DWORD* pPassword4);</code>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid.<br>KeyIndex &lt;0 or KeyIndex &gt; 14.
'''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'''


== Get user counts ==
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
<tr>
<td>*pPassword1</td>
<td>[in] Password 1</td>
</tr>
<tr>
<td>*pPassword2</td>
<td>[in] Password 2</td>
</tr>
<tr>
<td>*pPassword3</td>
<td>[in] Password 3</td>
</tr>
<tr>
<td>*pPassword4</td>
<td>[in] Password 4</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_Get_UserCount( WORD* handle ,<br>WORD* Count ) ;</code>
'''Return values'''


'''Description'''<br>UniKey Drive can enable 32 concurrent users to logon. This function can be called to get the number of logon users.
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
<tr>
<td>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID</td>
<td>202</td>
<td>Wrong password or UniKey HID</td>
</tr>
</table>


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*Count [in]Number of logon users returned
<br>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_KEY_INDEX 239 The key handle is invalid.<br>KeyIndex &lt;0 or KeyIndex &gt; 14.
=== Log off the Active User ===


'''API Prototype'''


<code>long UniKey_Logoff(WORD* pHandle);</code>


== Only allow one user to logon ==
'''Description'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_Logon_Single( WORD* pHandle , <br>DWORD* pPassword1 ,<br>DWORD* pPassword2 , <br>DWORD* pPassword3 , <br>DWORD* pPassword4 ) ;</code>
After calling this function, the active user will be logged out, does not affect other users’ login status.


'''Description'''<br>After calling this function, UniKey Drive only allows the active user to logon and other users will not be allowed to logon.
'''Parameters'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle<br>*pPassword1 [in]Password 1<br>*pPassword2 [in]Password 2<br>*pPassword3 [in]Password 3<br>*pPassword4 [in]Password 4
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success<br>ERROR_UNIKEY_INVALID_PASSWORD_OR_ID 202 The password or ID is invalid.
'''Return values'''


== <br>Logoff the active user ==
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


<br>'''API Prototype'''<br><code>long __stdcall UniKey_Logoff( WORD* pHandle ) ;</code>
<br>


<br>'''Description'''<br>After calling this function, the active user will be logoff, without affecting other users’ logon status.
=== Log off all Users ===


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle
'''API Prototype'''


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success
<code>long UniKey_Logoff_All(WORD* pHandle);</code>


== <br>Logoff all the users ==
'''Description'''


<br>'''API Prototype'''<br><code>long __stdcall UniKey_Logoff_All( WORD* pHandle ) ;</code>
After calling this function, all users will be logged off.


'''Description'''<br>After calling this function, all the users will be logoff.
'''Parameters'''


'''Parameters'''<br>Parameter Meaning<br>*pHandle [in]Device handle
<table class="wikitable">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>*pHandle</td>
<td>[in] Device handle</td>
</tr>
</table>


'''Return values'''<br>Marco Value Meaning<br>SUCCESS 0 Success&nbsp;
'''Return values'''


<br>&lt;a _fcknotitle="true" href="Category:UniKey_APIs"&gt;UniKey_APIs&lt;/a&gt;
<table class="wikitable">
<tr>
<th>Result</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>SUCCESS</td>
<td>0</td>
<td>Success</td>
</tr>
</table>


<br>
<br>

Latest revision as of 10:27, 2 August 2016


UniKey API Reference

A WORD is defined to be a 16-bit unsigned integer, while a DWORD is a 32-bit unsigned integer. These should be defined as types of that size regardless of platform.

Find a UniKey dongle

API Prototype

long UniKey_Find(WORD* pHandle, DWORD* pSetting1, DWORD* pSetting2);

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

long UniKey_Find_Next(WORD* pHandle, DWORD* pSetting1, DWORD* pSetting2);

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

long UniKey_User_Logon(WORD* pHandle, WORD* pPassword1, WORD* pPassword2);

For UniKey Drive, the API Prototype is

UniKey_User_Logon(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2);

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

long UniKey_Vender_Logon(WORD* pHandle, WORD* pPassword1, WORD* pPassword2, WORD* pPassword3, WORD* pPassword4);

For UniKey Drive, the API Prototype is

UniKey_Vender_Logon(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2, DWORD* pPassword3, DWORD* pPassword4);

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

long UniKey_Logoff(WORD* pHandle);

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

long UniKey_Get_Type(WORD* pHandle, DWORD* type);

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

long UniKey_Read_Memory(WORD* pHandle, WORD* pStartAddress, WORD* pBufferLength, BYTE* pBuffer);

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

long UniKey_Write_Memory(WORD* pHandle, WORD* pStartAddress, WORD* pBufferLength, BYTE* pBuffer);

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

long UniKey_Random(WORD* pHandle, WORD* pReturn1, WORD* pReturn2, WORD* pReturn3, WORD* pReturn4);

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

long UniKey_Seed(WORD* pHandle, DWORD* pSeed, WORD* pReturn1, WORD* pReturn2, WORD* pReturn3, WORD* pReturn4);

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

long UniKey_Write_SoftID(WORD* pHandle, DWORD* pSoftID);

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

long UniKey_Read_SoftID(WORD* pHandle, DWORD* pSoftID);

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

long UniKey_Set_Module(WORD* pHandle, WORD* pModule, WORD* pValue, WORD* pDecrease);

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

long UniKey_Get_Module(WORD* pHandle, WORD* pModule, WORD* pValue);

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

long UniKey_Check_Module(WORD* pHandle, WORD* pModule, WORD* pValue, WORD* pDecrease);

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

long UniKey_Write_Arithmetic(WORD* pHandle, WORD* pStartAddress, BYTE* pBuffer);

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

long UniKey_Calculate1(WORD* pHandle, DWORD* pStartAddress, DWORD* pModule, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);

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
*pRegA [in, out] Register A
*pRegB [in, out] Register B
*pRegC [in, out] Register C
*pRegD [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

long UniKey_Calculate2(WORD* pHandle, DWORD* pStartAddress, DWORD* pSeed, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);

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)
*pRegA [in, out] Register A
*pRegB [in, out] Register B
*pRegC [in, out] Register C
*pRegD [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

long UniKey_Calculate3(WORD* pHandle, DWORD* pStartAddress, DWORD* pModule, WORD* pRegA, WORD* pRegB, WORD* pRegC, WORD* pRegD);

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
*pRegA [in, out] Register A
*pRegB [in, out] Register B
*pRegC [in, out] Register C
*pRegD [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

long UniKey_Module_Decrease(WORD* pHandle, WORD* pModule);

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

long UniKey_Generate_New_Password(WORD* pHandle, DWORD* pSeed, WORD* pPassword1, WORD* pPassword2, WORD* pPassword3, WORD* pPassword4);

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!




  1. The dongle will automatically log off after a new set of passwords have been generated.
  2. The dongle will be fully formatted when a new password is generated.
  3. A file including the new passwords and seed will be created in the working directory.


Generate a New Encryption Key

API Prototype

long UniKey_Generate_Key(WORD* pHandle, DWORD* pKeyNumber);

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



  1. This function will delete the original key in the key storage, and generate a new key.
  2. The data encrypted by the old key cannot be decrypted by the new key.
  3. Each key is 128-bits long.


Generate a New Encryption Key via Seed

API Prototype

long UniKey_Generate_Key_Via_Seed(WORD* pHandle, DWORD* pKeyNumber, WORD pSeed1, WORD pSeed2, WORD pSeed3, WORD pSeed4);

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



  1. This function will delete the original key in the key storage, and generate a new key via seed.
  2. The data encrypted by the old key cannot be decrypted by the new key.
  3. Each key is 128-bit long.


Encrypt the Buffer with a Specific Encryption Key

API Prototype

long UniKey_Encrypt(WORD* pHandle, DWORD* pBufferLength, DWORD* pKeyNumber, BYTE* pBuffer);

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

long UniKey_Decrypt(WORD* pHandle, DWORD* pBufferLength, DWORD* pKeyNumber, BYTE* pBuffer);

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

long UniKey_MD5(WORD* pHandle, DWORD* pBufferLength, DWORD* pType, BYTE* pBuffer);

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

long UniKey_Read_UpdateTag(WORD* pHandle, DWORD* pUpdateTag);

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

long UniKey_Write_UpdateTag(WORD* pHandle, DWORD* pUpdateTag);

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

long UniKey_Get_Version(WORD* pHandle, DWORD* pVersion);

Description

Get the current UniKey library version.

Parameters

Parameter Description
*pHandle [in] Dongle handle
*pVersion [out] UniKey library version


Lock a UniKey Dongle

API Prototype

long UniKey_Lock(WORD *pHandle)

Description

Create a mutex to lock the UniKey dongle.

Parameters

Parameter Description
*pHandle [in] Dongle handle

Return values

Result Value Description
SUCCESS 0 Success
ERROR_UNIKEY_ALREADY_LOCKED 236 Dongle already locked (when attempting to lock twice, or open after locking a dongle)


Unlock a UniKey Dongle

API Prototype

long UniKey_UnLock(WORD *pHandle)

Description

Free the mutex to unlock the UniKey dongle.

Parameters

Parameter Description
*pHandle [out] Dongle handle

Return values

Result Value Description
SUCCESS 0 Success


UniKey Time API Reference

Get UniKey Time

API Prototype

long UniKey_Get_Time(WORD* pHandle, DWORD* pYear, DWORD* pMonth, WORD* pDay, WORD* pHour, WORD* pMinute, WORD* pSecond);

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

long UniKey_Set_Time(WORD* pHandle, DWORD* pYear, DWORD* pMonth, WORD* pDay, WORD* pHour, WORD* pMinute, WORD* pSecond);

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

long UniKey_Set_Time_Now(WORD* pHandle);

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

long UniKey_Erase_Time_Module(WORD* pHandle, DWORD* pModule);

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

long UniKey_Set_Time_Module_Start_Time(WORD* pHandle, DWORD* pModule, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);

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

long UniKey_Set_Time_Module_Start_Time_Now(WORD* pHandle, DWORD* pModule);

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

long UniKey_Set_Time_Module_Start_Time_Now_PC(WORD* pHandle, DWORD* pModule);

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

long UniKey_Set_Time_Module_End_Time(WORD* pHandle, DWORD* pModule, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);

Description

Set a real-time module’s end time.

Parameters

Parameter Description
*pHandle [in] Dongle handle
*pHandle [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

long UniKey_Set_Time_Module_Duration(WORD* pHandle, DWORD* pModule, DWORD* pDay, WORD* pHour);

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

long UniKey_Check_Time_Module(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pYear, WORD* pMonth, WORD* pDay, WORD* pHour);

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

long UniKey_Check_Time_Module_Now(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pRemainHours);

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

long UniKey_Check_Time_Module_Now_PC(WORD* pHandle, DWORD* pModule, DWORD* pRemainDays, WORD* pRemainHours);

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

long UniKey_FS_Init(WORD* pHandle, DWORD* PW1, DWORD* PW2, DWORD* PW3, DWORD* PW4);

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

long UniKey_FS_Format(WORD* pHandle);

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

long UniKey_FS_CreateFile(WORD* pHandle, BYTE* filename);

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

long UniKey_FS_DeleteFile(WORD* pHandle, BYTE* filename);

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

long UniKey_FS_File_Open(WORD* pHandle, BYTE* filename);

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

long UniKey_FS_Get_Free_Size(WORD* pHandle, DWORD* usedsize, DWORD* freesize);

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

long UniKey_FS_File_Modify_Data(WORD* pHandle, DWORD* offset, DWORD* len, BYTE* buffer);

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

long UniKey_FS_File_Append_Data(WORD* pHandle, DWORD* len, BYTE* buffer);

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

long UniKey_FS_File_Read_Data(WORD* pHandle, DWORD* offset, DWORD* len, BYTE* buffer);

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

long UniKey_FS_File_Close(WORD* pHandle, BYTE* filename);

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

long UniKey_FS_File_Get_List(WORD* pHandle, DWORD* filecount, BYTE* filelist);

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

long UniKey_FS_File_Get_Size(WORD* pHandle, DWORD* filesize);

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

long UniKey_FS_Set_Password(WORD* pHandle, DWORD* PW1, DWORD* PW2, DWORD* PW3, DWORD* PW4);

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

long UniKey_RSA_Generate_Key(WORD* pHandle, WORD* KeyIndex);

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

long UniKey_DES_Generate_Key(WORD* pHandle, DWORD* KeyIndex);

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

long UniKey_RSA_Get_Key_Counts(WORD* pHandle, DWORD* KeyIndexs);

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

long UniKey_DES_Get_Key_Counts(WORD* pHandle, DWORD* KeyIndexs);

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

long UniKey_RSA_Encrypt(WORD* pHandle, WORD* KeyIndex, DWORD* Encrypt_Len, BYTE* Buffer);

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

long UniKey_RSA_Decrypt(WORD* pHandle, WORD* KeyIndex, DWORD* Decrypt_Len, BYTE* Buffer);

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

long UniKey_DES1_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);

long UniKey_DES2_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);

long UniKey_DES3_Encrypt(WORD* pHandle, WORD* EncryptMode, WORD* KeyIndex, DWORD* Len, BYTE* Buffer);

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

long UniKey_DES1_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);

long UniKey_DES2_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);

long UniKey_DES3_Decrypt(WORD* pHandle, WORD* DecryptMode, WORD* KeyIndex, DWORD *Len, BYTE* Buffer);

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

long UniKey_RSA_Del_Key(WORD* pHandle, WORD* KeyIndex);

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

long UniKey_DES_Del_Key(WORD* pHandle, WORD* KeyIndex);

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

long UniKey_Get_UserCount(WORD* pHandle, WORD* Count);

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

long UniKey_Logon_Single(WORD* pHandle, DWORD* pPassword1, DWORD* pPassword2, DWORD* pPassword3, DWORD* pPassword4);

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

long UniKey_Logoff(WORD* pHandle);

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

long UniKey_Logoff_All(WORD* pHandle);

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