UniKey API Reference Java Example: Difference between revisions
From SecuTech Wiki
Jump to navigationJump to search
Initial Example submit |
m Indexing |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[category:UniKey API]] | |||
An example of utilizing the API in Java. | An example of utilizing the API in Java. | ||
| Line 6: | Line 8: | ||
public static void UniKeyRTCSample() | public static void UniKeyRTCSample() | ||
{ | { | ||
KeyObj mUniKey=new KeyObj(); | KeyObj mUniKey = new KeyObj(); | ||
short func; | short func; | ||
short[] handle=new short[1]; | short[] handle = new short[1]; | ||
int[] lp1=new int[1]; | int[] lp1 = new int[1]; | ||
int[] lp2=new int[2]; | int[] lp2 = new int[2]; | ||
short[] p1=new short[1]; | short[] p1 = new short[1]; | ||
short[] p2=new short[1]; | short[] p2 = new short[1]; | ||
short[] p3=new short[1]; | short[] p3 = new short[1]; | ||
short[] p4=new short[1]; | short[] p4 = new short[1]; | ||
byte[] buffer=new byte[1024]; | byte[] buffer = new byte[1024]; | ||
long | long retval; | ||
short[] rc= new short[4]; | short[] rc = new short[4]; | ||
// find dongle | // find dongle | ||
retval = mUniKey.UniKey_Find(handle,lp1,lp2); | retval = mUniKey.UniKey_Find(handle, lp1, lp2); | ||
if (retval==mUniKey.SUCCESS) | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Find UniKey:"+lp1[0]); | { | ||
System.out.println("Find UniKey:" + lp1[0]); | |||
} | |||
else | else | ||
{ | { | ||
System.out.println("No UniKey found | System.out.println("No UniKey found."); | ||
return; | return; | ||
} | } | ||
// logon dongle | // logon dongle | ||
p1[0] = 1234; | p1[0] = 1234; | ||
| Line 32: | Line 38: | ||
p3[0] = 1234; | p3[0] = 1234; | ||
p4[0] = 1234; | p4[0] = 1234; | ||
retval = mUniKey.UniKey_Vender_Logon(handle,p1,p2,p3,p4); | |||
if (retval==mUniKey.SUCCESS) | retval = mUniKey.UniKey_Vender_Logon(handle, p1, p2, p3, p4); | ||
System.out.println("Logon UniKey:"+lp1[0]); | if (retval == mUniKey.SUCCESS) | ||
{ | |||
System.out.println("Logon UniKey:" + lp1[0]); | |||
} | |||
else | else | ||
{ | { | ||
| Line 40: | Line 49: | ||
return; | return; | ||
} | } | ||
//UNIKEY_SET_TIME_NOW , time value from pc time | |||
retval = mUniKey.UniKey_Set_Time_Now(handle); | |||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Set Time okay:"+lp1[0]); | { | ||
System.out.println("Set Time okay:" + lp1[0]); | |||
} | } | ||
else | else | ||
| Line 51: | Line 61: | ||
return; | return; | ||
} | } | ||
//UNIKEY_GET_TIME | //UNIKEY_GET_TIME | ||
retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4); | retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Get Time okay:"+lp1[0]); | { | ||
System.out. | System.out.println("Get Time okay:" + lp1[0]); | ||
System.out.print("date: " + lp1[0] + "-" + lp2[0] + "-" + p1[0]); | |||
System.out.println(" time:" + p2[0] + ":" + p3[0] + ":" + p4[0]); | |||
} | } | ||
else | else | ||
| Line 63: | Line 75: | ||
return; | return; | ||
} | } | ||
System.out.println("Test time module.\n"); | System.out.println("Test time module.\n"); | ||
lp1[0] = 0; | lp1[0] = 0; | ||
lp2[0] = 0; | lp2[0] = 0; | ||
retval = mUniKey.UniKey_Erase_Time_Module(handle, lp1); | retval = mUniKey.UniKey_Erase_Time_Module(handle, lp1); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Erase Time module okay:"+lp1[0]); | { | ||
System.out.println("Erase Time module okay:" + lp1[0]); | |||
} | } | ||
else | else | ||
| Line 75: | Line 89: | ||
return; | return; | ||
} | } | ||
lp1[0] = 0; | lp1[0] = 0; | ||
lp2[0] = 0; | lp2[0] = 0; | ||
retval = mUniKey.UniKey_Set_Time_Module_Start_Time_Now(handle, lp1); | retval = mUniKey.UniKey_Set_Time_Module_Start_Time_Now(handle, lp1); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Set Time module start time okay:"+lp1[0]); | { | ||
}else{ | System.out.println("Set Time module start time okay:" + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Set Time module start time error:" + retval); | System.out.println("Set Time module start time error:" + retval); | ||
return; | return; | ||
} | } | ||
lp2[0] = 0;//days | |||
p1[0] = 1;//hours | lp2[0] = 0; //days | ||
p1[0] = 1; //hours | |||
retval = mUniKey.UniKey_Set_Time_Module_Duration(handle, lp1, lp2, p1); | retval = mUniKey.UniKey_Set_Time_Module_Duration(handle, lp1, lp2, p1); | ||
if(retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Set Time module end time okay:"+lp1[0]); | { | ||
}else{ | System.out.println("Set Time module end time okay:" + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Set Time module end time error:" + retval); | System.out.println("Set Time module end time error:" + retval); | ||
return; | return; | ||
} | } | ||
retval = mUniKey.UniKey_Check_Time_Module_Now(handle, lp1); | retval = mUniKey.UniKey_Check_Time_Module_Now(handle, lp1); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
{ | |||
System.out.println("checktime module : okay.\n"); | System.out.println("checktime module : okay.\n"); | ||
} | } | ||
if (retval==mUniKey.ERROR_UNIEKY_COMOPARE_TIME_MODULE){ | else if (retval == mUniKey.ERROR_UNIEKY_COMOPARE_TIME_MODULE) | ||
{ | |||
System.out.println("checktime module : error time later than start time!, code: " + retval + ".\n"); | |||
} | } | ||
if (retval==mUniKey.ERROR_UNIEKY_TIME_MODULE_OVERDUR){ | else if (retval == mUniKey.ERROR_UNIEKY_TIME_MODULE_OVERDUR) | ||
System.out.println("checktime module : overdue, code: "+retval+". | { | ||
System.out.println("checktime module : overdue, code: " + retval + ". \n"); | |||
} | } | ||
//test if module over | |||
//test if module over duration | |||
retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4); | retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4); | ||
if(retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
{ | |||
; | ; | ||
}else{ | } | ||
else | |||
{ | |||
System.out.println("Get Time error:" + retval); | System.out.println("Get Time error:" + retval); | ||
return; | return; | ||
} | } | ||
p3[0] = p1[0]; | |||
p4[0] = p2[0]; | p3[0] = p1[0]; | ||
p1[0] = (short)lp1[0]; | p4[0] = p2[0]; | ||
p2[0] = (short)lp2[0]; | p1[0] = (short)lp1[0]; | ||
lp1[0] = 0; | p2[0] = (short)lp2[0]; | ||
p4[0] += 2; | lp1[0] = 0; | ||
p4[0] += 2; | |||
retval = mUniKey.UniKey_Check_Time_Module(handle, lp1, p1, p2, p3, p4); | retval = mUniKey.UniKey_Check_Time_Module(handle, lp1, p1, p2, p3, p4); | ||
if(retval==mUniKey.SUCCESS){ | if(retval == mUniKey.SUCCESS) | ||
{ | |||
System.out.println("checktime module okay when no need.\n"); | System.out.println("checktime module okay when no need.\n"); | ||
} | } | ||
retval = mUniKey.UniKey_Logoff(handle); | retval = mUniKey.UniKey_Logoff(handle); | ||
if(retval!=mUniKey.SUCCESS){ | if(retval != mUniKey.SUCCESS) | ||
{ | |||
System.out.println("Logoff failed!"); | System.out.println("Logoff failed!"); | ||
return; | return; | ||
| Line 131: | Line 163: | ||
System.out.println("Logoff UniKey"); | System.out.println("Logoff UniKey"); | ||
} | } | ||
public static void UniKeySample() | public static void UniKeySample() | ||
{ | { | ||
KeyObj mUniKey=new KeyObj(); | KeyObj mUniKey = new KeyObj(); | ||
short func; | short func; | ||
short[] handle=new short[1]; | short[] handle = new short[1]; | ||
int[] lp1=new int[1]; | int[] lp1 = new int[1]; | ||
int[] lp2=new int[2]; | int[] lp2 = new int[2]; | ||
short[] p1=new short[1]; | short[] p1 = new short[1]; | ||
short[] p2=new short[1]; | short[] p2 = new short[1]; | ||
short[] p3=new short[1]; | short[] p3 = new short[1]; | ||
short[] p4=new short[1]; | short[] p4 = new short[1]; | ||
byte[] buffer=new byte[1024]; | byte[] buffer = new byte[1024]; | ||
long | long retval; | ||
short[] rc= new short[4]; | short[] rc = new short[4]; | ||
// find dongle | // find dongle | ||
retval = mUniKey.UniKey_Find(handle,lp1,lp2); | retval = mUniKey.UniKey_Find(handle, lp1, lp2); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Find UniKey:"+lp1[0]); | { | ||
}else{ | System.out.println("Find UniKey:" + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("No UniKey found:"); | System.out.println("No UniKey found:"); | ||
return; | return; | ||
} | } | ||
// logon dongle | // logon dongle | ||
p1[0] = 1234; | p1[0] = 1234; | ||
| Line 159: | Line 196: | ||
p3[0] = 1234; | p3[0] = 1234; | ||
p4[0] = 1234; | p4[0] = 1234; | ||
retval = mUniKey.UniKey_Vender_Logon(handle,p1,p2,p3,p4); | retval = mUniKey.UniKey_Vender_Logon(handle, p1, p2, p3, p4); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Logon UniKey:"+lp1[0]); | { | ||
}else{ | System.out.println("Logon UniKey:" + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// write memory | // write memory | ||
p1[0]=3; | p1[0]=3; | ||
p2[0]=5; | p2[0]=5; | ||
buffer[0]='A'; | buffer[0] = 'A'; buffer[1] = 'C'; buffer[2] = 'c'; | ||
buffer[3]='B'; | buffer[3] = 'B'; buffer[4] = 'D'; | ||
retval = mUniKey.UniKey_Write_Memory(handle,p1,p2,buffer); | retval = mUniKey.UniKey_Write_Memory(handle, p1, p2, buffer); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
{ | |||
System.out.println("Write UniKey Successfully"); | System.out.println("Write UniKey Successfully"); | ||
}else{ | } | ||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// read memory | // read memory | ||
p1[0]=3; | p1[0]=3; | ||
p2[0]=5; | p2[0]=5; | ||
for(int m=0;m<5;m++)buffer[m]=0; | for (int m = 0; m < 5; m++) | ||
retval = mUniKey.UniKey_Read_Memory(handle,p1,p2,buffer); | { | ||
if (retval==mUniKey.SUCCESS){ | buffer[m] = 0; | ||
} | |||
retval = mUniKey.UniKey_Read_Memory(handle, p1, p2, buffer); | |||
if (retval == mUniKey.SUCCESS) | |||
{ | |||
System.out.println("Read UniKey Successfully:"); | System.out.println("Read UniKey Successfully:"); | ||
}else{ | } | ||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// random | // random | ||
retval = mUniKey.UniKey_Random(handle,p1,p2,p3,p4); | retval = mUniKey.UniKey_Random(handle, p1, p2, p3, p4); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Random Successfully:" +p1[0]); | { | ||
}else{ | System.out.println("Random Successfully:" + p1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// seed | // seed | ||
lp1[0]=12345678; | lp1[0] = 12345678; | ||
retval = mUniKey.UniKey_Seed(handle,lp1,p1,p2,p3,p4); | retval = mUniKey.UniKey_Seed(handle, lp1, p1, p2, p3, p4); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Seed: "+p1[0]+","+p2[0]+","+p3[0]+","+p4[0]); | { | ||
}else{ | System.out.println("Seed: " + p1[0] + "," + p2[0] + "," + p3[0] + "," + p4[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// write soft id | |||
lp1[0] = 8888; | |||
retval = mUniKey.UniKey_Write_SoftID(handle,lp1); | retval = mUniKey.UniKey_Write_SoftID(handle, lp1); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Write SoftID: "+lp1[0]); | { | ||
}else{ | System.out.println("Write SoftID: " + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// read soft id | // read soft id | ||
lp1[0]=0; | lp1[0] = 0; | ||
retval = mUniKey.UniKey_Read_SoftID(handle,lp1); | retval = mUniKey.UniKey_Read_SoftID(handle, lp1); | ||
if (retval==mUniKey.SUCCESS){ | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Read SoftID: "+lp1[0]); | { | ||
}else{ | System.out.println("Read SoftID: " + lp1[0]); | ||
} | |||
else | |||
{ | |||
System.out.println("Found error:" + retval); | System.out.println("Found error:" + retval); | ||
return; | return; | ||
} | } | ||
// write updatetag | // write updatetag | ||
lp1[0]=66666; | lp1[0] = 66666; | ||
retval = mUniKey.UniKey_Write_UpDataTag(handle,lp1); | retval = mUniKey.UniKey_Write_UpDataTag(handle, lp1); | ||
if (retval==mUniKey.SUCCESS) | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Write UpdateTag: "+lp1[0]); | { | ||
System.out.println("Write UpdateTag: " + lp1[0]); | |||
} | |||
else | else | ||
{ | { | ||
| Line 235: | Line 305: | ||
return; | return; | ||
} | } | ||
// read updatetag | // read updatetag | ||
lp1[0]=0; | lp1[0] = 0; | ||
retval = mUniKey.UniKey_Read_UpDataTag(handle,lp1); | retval = mUniKey.UniKey_Read_UpDataTag(handle, lp1); | ||
if (retval==mUniKey.SUCCESS) | if (retval == mUniKey.SUCCESS) | ||
System.out.println("Read UpdateTag: "+lp1[0]); | { | ||
System.out.println("Read UpdateTag: " + lp1[0]); | |||
} | |||
else | else | ||
{ | { | ||
| Line 245: | Line 318: | ||
return; | return; | ||
} | } | ||
// set module | // set module | ||
p1[0]=7; | p1[0] = 7; | ||
p2[0]=0x2121; | p2[0] = 0x2121; | ||
p3[0]=0; | p3[0] = 0; | ||
retval = mUniKey.UniKey_Set_Module(handle,p1,p2,p3); | retval = mUniKey.UniKey_Set_Module(handle, p1, p2, p3); | ||
if(retval!=mUniKey.SUCCESS) | if (retval != mUniKey.SUCCESS) | ||
{ | { | ||
System.out.println("Set module failed!"); | System.out.println("Set module failed!"); | ||
return; | return; | ||
} | } | ||
System.out.println("Set module 7,pass="+p2[0]+",Decreasement not | System.out.println("Set module 7, pass=" + p2[0] + ", Decreasement not allowed!"); | ||
// check module | |||
p1[0] = 7; | |||
retval = mUniKey.UniKey_Check_Module(handle, p1, p2, p3); | |||
if(retval != mUniKey.SUCCESS) | |||
if(retval!=mUniKey.SUCCESS){ | { | ||
System.out.println("Chech Module Failed!"); | System.out.println("Chech Module Failed!"); | ||
return; | return; | ||
} | } | ||
System.out.print("Check module 7:"); | System.out.print("Check module 7:"); | ||
if(p2[0]!=0){ | if (p2[0] != 0) | ||
{ | |||
System.out.println("valid!"); | System.out.println("valid!"); | ||
}else{ | } | ||
else | |||
{ | |||
System.out.println("invalid!"); | System.out.println("invalid!"); | ||
} | } | ||
if(p3[0]!=0){ | if (p3[0] != 0) | ||
System.out.println("Allow | { | ||
}else{ | System.out.println("Allow decreasement!"); | ||
System.out.println(" | } | ||
else | |||
{ | |||
System.out.println("Decreasement not allowed!"); | |||
} | } | ||
// generate new password | // generate new password | ||
// if you really want to change password, please de-comment these codes | // if you really want to change password, please de-comment these codes | ||
// lp1[0]=1234; | // lp1[0] = 1234; | ||
// retval = | // retval = mUniKey.UniKey_Generate_New_Password(handle,lp1,p1,p2,p3,p4); | ||
// if (retval != mUniKey.SUCCESS) | |||
// if(retval!=mUniKey.SUCCESS){ | // { | ||
// | // System.out.println("generate new password!"); | ||
// | // return; | ||
// } | // } | ||
// System.out.println("new password: | // System.out.println("new password: p1=" + p1[0] + ",p2=" + p2[0] + ",p3=" + p3[0] + ",p4=" + p4[0]); | ||
retval = mUniKey.UniKey_Logoff(handle); | |||
if (retval != mUniKey.SUCCESS) | |||
if(retval!=mUniKey.SUCCESS){ | { | ||
System.out.println("Logoff failed!"); | System.out.println("Logoff failed!"); | ||
return; | return; | ||
| Line 294: | Line 376: | ||
System.out.println("Logoff UniKey"); | System.out.println("Logoff UniKey"); | ||
} | } | ||
public static void main(String[] args){ | public static void main(String[] args){ | ||
UniKeySample(); | UniKeySample(); | ||
Latest revision as of 11:31, 14 July 2016
An example of utilizing the API in Java.
class sample
{
public static void UniKeyRTCSample()
{
KeyObj mUniKey = new KeyObj();
short func;
short[] handle = new short[1];
int[] lp1 = new int[1];
int[] lp2 = new int[2];
short[] p1 = new short[1];
short[] p2 = new short[1];
short[] p3 = new short[1];
short[] p4 = new short[1];
byte[] buffer = new byte[1024];
long retval;
short[] rc = new short[4];
// find dongle
retval = mUniKey.UniKey_Find(handle, lp1, lp2);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Find UniKey:" + lp1[0]);
}
else
{
System.out.println("No UniKey found.");
return;
}
// logon dongle
p1[0] = 1234;
p2[0] = 1234;
p3[0] = 1234;
p4[0] = 1234;
retval = mUniKey.UniKey_Vender_Logon(handle, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Logon UniKey:" + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
//UNIKEY_SET_TIME_NOW , time value from pc time
retval = mUniKey.UniKey_Set_Time_Now(handle);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Set Time okay:" + lp1[0]);
}
else
{
System.out.println("Set Time error:" + retval);
return;
}
//UNIKEY_GET_TIME
retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Get Time okay:" + lp1[0]);
System.out.print("date: " + lp1[0] + "-" + lp2[0] + "-" + p1[0]);
System.out.println(" time:" + p2[0] + ":" + p3[0] + ":" + p4[0]);
}
else
{
System.out.println("Get Time error:" + retval);
return;
}
System.out.println("Test time module.\n");
lp1[0] = 0;
lp2[0] = 0;
retval = mUniKey.UniKey_Erase_Time_Module(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Erase Time module okay:" + lp1[0]);
}
else
{
System.out.println("Erase Time module error:" + retval);
return;
}
lp1[0] = 0;
lp2[0] = 0;
retval = mUniKey.UniKey_Set_Time_Module_Start_Time_Now(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Set Time module start time okay:" + lp1[0]);
}
else
{
System.out.println("Set Time module start time error:" + retval);
return;
}
lp2[0] = 0; //days
p1[0] = 1; //hours
retval = mUniKey.UniKey_Set_Time_Module_Duration(handle, lp1, lp2, p1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Set Time module end time okay:" + lp1[0]);
}
else
{
System.out.println("Set Time module end time error:" + retval);
return;
}
retval = mUniKey.UniKey_Check_Time_Module_Now(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("checktime module : okay.\n");
}
else if (retval == mUniKey.ERROR_UNIEKY_COMOPARE_TIME_MODULE)
{
System.out.println("checktime module : error time later than start time!, code: " + retval + ".\n");
}
else if (retval == mUniKey.ERROR_UNIEKY_TIME_MODULE_OVERDUR)
{
System.out.println("checktime module : overdue, code: " + retval + ". \n");
}
//test if module over duration
retval = mUniKey.UniKey_Get_Time(handle, lp1, lp2, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
;
}
else
{
System.out.println("Get Time error:" + retval);
return;
}
p3[0] = p1[0];
p4[0] = p2[0];
p1[0] = (short)lp1[0];
p2[0] = (short)lp2[0];
lp1[0] = 0;
p4[0] += 2;
retval = mUniKey.UniKey_Check_Time_Module(handle, lp1, p1, p2, p3, p4);
if(retval == mUniKey.SUCCESS)
{
System.out.println("checktime module okay when no need.\n");
}
retval = mUniKey.UniKey_Logoff(handle);
if(retval != mUniKey.SUCCESS)
{
System.out.println("Logoff failed!");
return;
}
System.out.println("Logoff UniKey");
}
public static void UniKeySample()
{
KeyObj mUniKey = new KeyObj();
short func;
short[] handle = new short[1];
int[] lp1 = new int[1];
int[] lp2 = new int[2];
short[] p1 = new short[1];
short[] p2 = new short[1];
short[] p3 = new short[1];
short[] p4 = new short[1];
byte[] buffer = new byte[1024];
long retval;
short[] rc = new short[4];
// find dongle
retval = mUniKey.UniKey_Find(handle, lp1, lp2);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Find UniKey:" + lp1[0]);
}
else
{
System.out.println("No UniKey found:");
return;
}
// logon dongle
p1[0] = 1234;
p2[0] = 1234;
p3[0] = 1234;
p4[0] = 1234;
retval = mUniKey.UniKey_Vender_Logon(handle, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Logon UniKey:" + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// write memory
p1[0]=3;
p2[0]=5;
buffer[0] = 'A'; buffer[1] = 'C'; buffer[2] = 'c';
buffer[3] = 'B'; buffer[4] = 'D';
retval = mUniKey.UniKey_Write_Memory(handle, p1, p2, buffer);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Write UniKey Successfully");
}
else
{
System.out.println("Found error:" + retval);
return;
}
// read memory
p1[0]=3;
p2[0]=5;
for (int m = 0; m < 5; m++)
{
buffer[m] = 0;
}
retval = mUniKey.UniKey_Read_Memory(handle, p1, p2, buffer);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Read UniKey Successfully:");
}
else
{
System.out.println("Found error:" + retval);
return;
}
// random
retval = mUniKey.UniKey_Random(handle, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Random Successfully:" + p1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// seed
lp1[0] = 12345678;
retval = mUniKey.UniKey_Seed(handle, lp1, p1, p2, p3, p4);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Seed: " + p1[0] + "," + p2[0] + "," + p3[0] + "," + p4[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// write soft id
lp1[0] = 8888;
retval = mUniKey.UniKey_Write_SoftID(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Write SoftID: " + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// read soft id
lp1[0] = 0;
retval = mUniKey.UniKey_Read_SoftID(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Read SoftID: " + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// write updatetag
lp1[0] = 66666;
retval = mUniKey.UniKey_Write_UpDataTag(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Write UpdateTag: " + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// read updatetag
lp1[0] = 0;
retval = mUniKey.UniKey_Read_UpDataTag(handle, lp1);
if (retval == mUniKey.SUCCESS)
{
System.out.println("Read UpdateTag: " + lp1[0]);
}
else
{
System.out.println("Found error:" + retval);
return;
}
// set module
p1[0] = 7;
p2[0] = 0x2121;
p3[0] = 0;
retval = mUniKey.UniKey_Set_Module(handle, p1, p2, p3);
if (retval != mUniKey.SUCCESS)
{
System.out.println("Set module failed!");
return;
}
System.out.println("Set module 7, pass=" + p2[0] + ", Decreasement not allowed!");
// check module
p1[0] = 7;
retval = mUniKey.UniKey_Check_Module(handle, p1, p2, p3);
if(retval != mUniKey.SUCCESS)
{
System.out.println("Chech Module Failed!");
return;
}
System.out.print("Check module 7:");
if (p2[0] != 0)
{
System.out.println("valid!");
}
else
{
System.out.println("invalid!");
}
if (p3[0] != 0)
{
System.out.println("Allow decreasement!");
}
else
{
System.out.println("Decreasement not allowed!");
}
// generate new password
// if you really want to change password, please de-comment these codes
// lp1[0] = 1234;
// retval = mUniKey.UniKey_Generate_New_Password(handle,lp1,p1,p2,p3,p4);
// if (retval != mUniKey.SUCCESS)
// {
// System.out.println("generate new password!");
// return;
// }
// System.out.println("new password: p1=" + p1[0] + ",p2=" + p2[0] + ",p3=" + p3[0] + ",p4=" + p4[0]);
retval = mUniKey.UniKey_Logoff(handle);
if (retval != mUniKey.SUCCESS)
{
System.out.println("Logoff failed!");
return;
}
System.out.println("Logoff UniKey");
}
public static void main(String[] args){
UniKeySample();
UniKeyRTCSample();
}
}