Add Original SDK
This commit is contained in:
322
Dinkey Pro 7.6.1/Samples/Java/DinkeyChange/DCSample.java
Normal file
322
Dinkey Pro 7.6.1/Samples/Java/DinkeyChange/DCSample.java
Normal file
@@ -0,0 +1,322 @@
|
||||
// A simple program illustrating how to use the DinkeyChange API in Java.
|
||||
// Copyright 2018 Microcosm Ltd.
|
||||
|
||||
import uk.microcosm.dinkeydongle.DinkeyChange;
|
||||
import uk.microcosm.dinkeydongle.DinkeyChangeException;
|
||||
import uk.microcosm.dinkeydongle.DongleToChange;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class DCSample
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String userChoice = "";
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
// Prompt the user for the DinkeyChange operation to perform
|
||||
System.out.println();
|
||||
System.out.println("1) Display information about dongles attached to this computer");
|
||||
System.out.println("2) Save diagnostic information to a file");
|
||||
System.out.println("3) Apply an update code from a file");
|
||||
System.out.println("4) Apply a short update code");
|
||||
System.out.println("5) Restore a Dinkey FD Lite dongle");
|
||||
System.out.println("6) Display this computer's machine ID");
|
||||
System.out.println("7) Download and install a temporary software key");
|
||||
System.out.println("8) Download and install a demo software key");
|
||||
System.out.print("Enter an option 1 to 8. Enter anything else to exit: ");
|
||||
try
|
||||
{
|
||||
userChoice = br.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
if (userChoice.equals("1"))
|
||||
{
|
||||
/* DinkeyChange.getDongles() - get information about dongles attached to this computer.
|
||||
This method returns an array of DongleToChange objects. You can use this method's arguments
|
||||
to control which dongles it searches for - see README.html for more information. */
|
||||
|
||||
int i;
|
||||
DongleToChange[] dongles;
|
||||
|
||||
try
|
||||
{ // Search for all types and models of dongle, with any product code
|
||||
dongles = DinkeyChange.getDongles(DinkeyChange.TYPE_MASK_ALL, DinkeyChange.MODEL_MASK_ALL, "");
|
||||
|
||||
for (i = 0; i < dongles.length; i++)
|
||||
{
|
||||
/* Display information about each dongle found that matched the search criteria.
|
||||
This information is needed by DinkeyRemote to create update codes for these dongles. */
|
||||
|
||||
System.out.println((i+1) + ": Dinkey " + dongles[i].typeAsString + " " + dongles[i].modelAsString);
|
||||
System.out.println("\tDongle Number: " + dongles[i].dongleNumber);
|
||||
System.out.println("\tProduct Code: " + dongles[i].productCode);
|
||||
System.out.println("\tUpdate Number: " + dongles[i].updateNumber);
|
||||
}
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("2"))
|
||||
{
|
||||
/* DinkeyChange.writeDiagnosticsToFile() - this method creates an encrypted DLPF file containing diagnostics
|
||||
and the parameters stored in each dongle currently attached to this computer. This file can be opened with DinkeyLook.
|
||||
This method can take a String or File argument, i.e. DinkeyChange.writeDiagnosticsToFile("out.dlpf")
|
||||
is exactly equivalent to DinkeyChange.writeDiagnosticsToFile(new File("out.dlpf")) */
|
||||
|
||||
String filename = null;
|
||||
|
||||
// Prompt for the name of the DLPF file to create.
|
||||
// This file's path can be absolute, or relative to the current working directory.
|
||||
// If the name does not include a ".dlpf" extension, it will automatically be added.
|
||||
System.out.print("Enter output filename: ");
|
||||
try
|
||||
{
|
||||
filename = br.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
try
|
||||
{ // If successful, DinkeyChange.writeDiagnosticsToFile() returns the full path to the file it created
|
||||
System.out.println("Diagnostics written to " + DinkeyChange.writeDiagnosticsToFile(new File(filename)));
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("3"))
|
||||
{
|
||||
/* DinkeyChange.applyUpdate(File) - this method takes a File object representing
|
||||
a secure update code file (DUCF file) and applies the code to the relevant dongle
|
||||
attached to this computer, updating the parameters stored in that dongle. */
|
||||
|
||||
File f;
|
||||
String filename = null;
|
||||
String confirmationCode;
|
||||
|
||||
// Prompt user for location of DUCF file.
|
||||
// The path to the file can be absolute, or relative to the current working directory
|
||||
System.out.print("Enter secure update code filename: ");
|
||||
try
|
||||
{
|
||||
filename = br.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
f = new File(filename); // Create a File object representing the DUCF file
|
||||
try
|
||||
{ // If successful, DinkeyChange.applyUpdate() returns the confirmation code for this update
|
||||
confirmationCode = Integer.toHexString(DinkeyChange.applyUpdate(f));
|
||||
System.out.println("Update code successfully applied. Confirmation code is " + confirmationCode);
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("4"))
|
||||
{
|
||||
/* DinkeyChange.applyUpdate(String) - this method takes a short secure update code
|
||||
and applies it to the relevant dongle attached to this computer, updating the parameters
|
||||
stored in that dongle. */
|
||||
|
||||
String updateCode = null;
|
||||
String confirmationCode;
|
||||
|
||||
// Prompt the user for the short update code
|
||||
System.out.print("Enter update code: ");
|
||||
try
|
||||
{
|
||||
updateCode = br.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
try
|
||||
{ // If successful, DinkeyChange.applyUpdate() returns the confirmation code for this update
|
||||
confirmationCode = Integer.toHexString(DinkeyChange.applyUpdate(updateCode));
|
||||
System.out.println("Update code successfully applied. Confirmation code is " + confirmationCode);
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("5"))
|
||||
{
|
||||
// DinkeyChange.restoreDinkeyFDLite() - restore a Dinkey FD Lite dongle
|
||||
|
||||
try
|
||||
{
|
||||
DinkeyChange.restoreDinkeyFDLite();
|
||||
System.out.println("Dinkey FD Lite restored successfully.");
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("6"))
|
||||
{
|
||||
// DinkeyChange.getMachineID() - get this computer's machine ID
|
||||
|
||||
String machineIDString;
|
||||
|
||||
try
|
||||
{
|
||||
machineIDString = Long.toHexString(DinkeyChange.getMachineID());
|
||||
System.out.println("The Machine ID is " + machineIDString);
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("7"))
|
||||
{
|
||||
// DinkeyChange.downloadTempSoftwareKey() - download and install a temporary software key
|
||||
|
||||
try
|
||||
{
|
||||
DinkeyChange.downloadTempSoftwareKey();
|
||||
System.out.println("The temporary software key has been downloaded successfully.");
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
else if (userChoice.equals("8"))
|
||||
{
|
||||
// DinkeyChange.downloadDemoSoftwareKey() - download and install a demo software key
|
||||
|
||||
String productCode = null;
|
||||
|
||||
// Prompt for the product code to use
|
||||
System.out.print("Enter product code of demo software key: ");
|
||||
try
|
||||
{
|
||||
productCode = br.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// This examples assumes that exactly one dongle model is set in the demo template
|
||||
// If multiple models are set in the template you will need to use the second parameter to specify which model to download and install
|
||||
DinkeyChange.downloadDemoSoftwareKey(productCode, DinkeyChange.SWKEY_MODEL_DEFAULT);
|
||||
System.out.println("The demo software key has been downloaded successfully.");
|
||||
}
|
||||
catch (DinkeyChangeException e)
|
||||
{
|
||||
displayError(e);
|
||||
}
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
|
||||
} // End of main()
|
||||
|
||||
|
||||
// An example of error reporting
|
||||
// Displays descriptions for some common error codes
|
||||
static void displayError(DinkeyChangeException e)
|
||||
{
|
||||
switch (e.getError())
|
||||
{
|
||||
case 401:
|
||||
System.out.println("Error! No dongles detected that meet the search criteria!");
|
||||
break;
|
||||
|
||||
case 409:
|
||||
System.out.println("Error! The dongle detected has not been programmed by DinkeyAdd.");
|
||||
break;
|
||||
|
||||
case 758:
|
||||
System.out.println("Error! Cannot open the update code file specified.");
|
||||
break;
|
||||
|
||||
case 759:
|
||||
System.out.println("Error! The file specified is not a valid update code file.");
|
||||
break;
|
||||
|
||||
case 762:
|
||||
case 763:
|
||||
case 764:
|
||||
System.out.println("Error! Update code is not in a correct format / update code file is corrupt.");
|
||||
break;
|
||||
|
||||
case 765:
|
||||
System.out.println("Error! The update code does not match any dongle attached to your machine.");
|
||||
break;
|
||||
|
||||
case 766:
|
||||
System.out.println("Error! The update number for this update code is too high. You need to first enter an update code that was previously sent to you.");
|
||||
break;
|
||||
|
||||
case 767:
|
||||
System.out.println("Error! You have already entered this update code.");
|
||||
break;
|
||||
|
||||
case 1905:
|
||||
System.out.println("Error! There is no software key available for download.");
|
||||
break;
|
||||
|
||||
case 1907:
|
||||
System.out.println("Error! The temporary software key has expired. Cannot download it.");
|
||||
break;
|
||||
|
||||
case 1910:
|
||||
System.out.println("Error! The software key has already been downloaded.");
|
||||
break;
|
||||
|
||||
case 1921:
|
||||
System.out.println("Error! You specified the 'default model' but there is more than one model available. You need to specify a specific dongle model.");
|
||||
break;
|
||||
|
||||
case 1922:
|
||||
System.out.println("Error! The model you requested is not available.");
|
||||
break;
|
||||
|
||||
case 1923:
|
||||
System.out.println("Error! The demo software key template has been disabled.");
|
||||
break;
|
||||
|
||||
case 1924:
|
||||
System.out.println("Error! You have run out of demo software key activations. You need to order some more.");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.err.println("DinkeyChange error " + e.getError() + ":" + e.getExtendedError());
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
} // End of class DCSample
|
||||
335
Dinkey Pro 7.6.1/Samples/Java/DinkeyChange/README.html
Normal file
335
Dinkey Pro 7.6.1/Samples/Java/DinkeyChange/README.html
Normal file
@@ -0,0 +1,335 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Using the DinkeyChange API with Java</title>
|
||||
<style>
|
||||
body {
|
||||
color: black;
|
||||
font-family: Verdana, Arial, Helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
margin: 25px auto;
|
||||
max-width: 800px;
|
||||
}
|
||||
p, ul, ol, table {
|
||||
margin-top: 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
ul.contents a {
|
||||
text-decoration: none;
|
||||
}
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
margin-top: 25px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
h2 {
|
||||
border-top: 1px solid gray;
|
||||
}
|
||||
table {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid black;
|
||||
padding: 0.5em;
|
||||
text-align: left;
|
||||
}
|
||||
.ui_element
|
||||
{ /* Use for things like program options and menu items */
|
||||
color: #008000;
|
||||
font-style: italic;
|
||||
}
|
||||
.filepath
|
||||
{ /* Use for paths and filenames */
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.manual
|
||||
{ /* Use when referring to user manual sections/chapters */
|
||||
font-style: italic;
|
||||
}
|
||||
.alert
|
||||
{
|
||||
border: 1px solid black;
|
||||
padding: 15px 15px 15px 58px;
|
||||
font-weight: bold;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 5px 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.important
|
||||
{
|
||||
background-color: #FFFDD0;
|
||||
background-image: url('data:image/png;base64,iVB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UQAmHgN1B9BFUK/AP09XaiDR07OoNDBApqtLT3R1VcrfYrFWtDHay9HNiTIM9EwGvbkZH+gbHCwNuW7xLXjoN7BOVkCWgPKI1iMykCc63LWoRcCKtgsgdyvcORUuyzQ1aU25nGFNnYq0bbzBQaRtI123cqKnVOXk2jAQpomwLISm4eTz5PP5slMuy09h01Pwp08q38rcqrdHtsF1KJM5Xo8CDzQWtJdD53fg+21whRBCS6dSsXgmY5iWhW6aCEBJifQ8PNel7LoUbbvsuK7ng3sYNj4Pf9tVqfMDr0fbQEeBnywBqOwb4lXggVqAWb02ExC7BuZ3w+JWOC8OHTpkReV/JaHsw0ARDh+F7bvg36/CPq+WFtFUCQgE6tDgZPrzEAjEHAm8Si5o9Wo78nNZIHWfx6qg/AiBRkTKjCNf9DOrVgUdAA9UpzboR36sjBII2uB7hhfRclXrVtwvm8BI0WhMYKIPlVECkwL8tfy/yX8BjYmrtt9ODsIAAAAASUVORK5CYII=');
|
||||
}
|
||||
.information
|
||||
{
|
||||
background-color: #EBF8FF;
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAYdEVYdFRpdGxlAERpYWxvZyBJbmZvcm1hdGlvbvUv0PgAAAAUdEVYdEF1dGhvcgBKYWt1YiBTdGVpbmVy5vv3LwAAACF0RVh0U291cmNlAGh0dHA6Ly9qaW1tYWMubXVzaWNoYWxsLmN6aWbjXgAACnJJREFUaIHVmX+MXFd1x7/n3Pvem5md3Z3ZXa+9P+z4Z5YYYtUkqYEAQlEQQgLRlsSkhQKVKjWthBAl/BOpTX+gNiptgxBEbWiRMDiCQCokVCgkEKBNDf4hQGuvHeMf63jt3eyP2ZnZmdl58+49p3/MTFhvHNvr3Q3q1Ry9OzN33vl+7jv33B9Dqor/z4V/0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n7S8fCVf/4W/Fyunlg8rLgtrXfM67sXbuk3i7SMrek7pdc3bK602uIXNV+oDUu2hB8FQNeGRqtA5YrYHQZhL9e9lkTgFfcrPl02mKXxvfy0oZoi9Rr9fK1yv8BQhlE2oxknwEAAAAASUVORK5CYII=');
|
||||
}
|
||||
.alert > p:last-child, .alert > ul:last-child, .alert > ol:last-child
|
||||
{
|
||||
/* Cancel double space at bottom of alert caused by above rule */
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.important .filepath, .information .filepath {
|
||||
/* Make filepaths stand out in sections that are already bold */
|
||||
font-weight: normal;
|
||||
}
|
||||
div.col_wrapper
|
||||
{
|
||||
clear: both;
|
||||
overflow: hidden;
|
||||
}
|
||||
div.two_col
|
||||
{
|
||||
width: 50%;
|
||||
float: left;
|
||||
}
|
||||
code {
|
||||
color: gray;
|
||||
white-space: nowrap;
|
||||
}
|
||||
pre {
|
||||
padding: 15px;
|
||||
background-color: #EEEEEE;
|
||||
}
|
||||
pre > code { /* Block level code snippets */
|
||||
white-space: pre; /* Override nowrap used for inline code */
|
||||
color: inherit;
|
||||
}
|
||||
code .comment
|
||||
{
|
||||
color: green;
|
||||
}
|
||||
code .keyword
|
||||
{
|
||||
font-weight: bold;
|
||||
color: blue;
|
||||
}
|
||||
code .string
|
||||
{
|
||||
color: #A00000;
|
||||
}
|
||||
code .constant
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Using the DinkeyChange API with Java</h1>
|
||||
<p>
|
||||
The DinkeyChange API allows you apply secure update codes to modify the information
|
||||
stored in Dinkey Pro and FD dongles directly from your Java application.
|
||||
The API also allows you to view the information needed to create these codes, and produce
|
||||
encrypted diagnostic files to help you troubleshoot any dongle-related problems your users might have.
|
||||
</p>
|
||||
<p>
|
||||
The <code>DinkeyChange</code> class provides a Java wrapper around the API, which is implemented by native libraries.
|
||||
If you are not familiar with calling native libraries, it is recommended that you read the Java documentation on the subject,
|
||||
especially the documentation for <code>System.loadLibrary()</code>,
|
||||
and how Java uses the system property <code>java.library.path</code> to locate native libraries.
|
||||
</p>
|
||||
<p>
|
||||
The native libraries and the classes described below are part of the <code>uk.microcosm.dinkeydongle</code> package.
|
||||
See the documentation for your development environment for details of how to include and reference this package in your project.
|
||||
<span class="filepath">dinkeydongle.jar</span> provides all of the Java classes in the <code>uk.microcosm.dinkeydongle</code> package in a single JAR file.
|
||||
This allows you to import the package much more easily in many Java IDEs. Note that the native libraries are <strong>not</strong> included in the JAR file.
|
||||
You will need to distribute with your software the native libraries for every platform that your software supports.
|
||||
</p>
|
||||
|
||||
<h2>The DinkeyChange Class</h2>
|
||||
<p>
|
||||
This class exposes the DinkeyChange API to Java programs.
|
||||
It contains only static methods and fields, and cannot be instantiated.
|
||||
</p>
|
||||
|
||||
<h3>Fields</h3>
|
||||
<p>
|
||||
Useful constants you can use in your code:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int MAX_USB_DEVICES</code> - maximum number of dongles that the API can return information about.</li>
|
||||
<li><code>static final int MAX_PRODCODE_LEN</code> - maximum length of a product code string.</li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values to use as the <code>typeMask</code> parameter of <code>DinkeyChange.getDongles()</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int TYPE_MASK_PRO</code> - search for Dinkey Pro dongles only.</li>
|
||||
<li><code>static final int TYPE_MASK_FD</code> - search for Dinkey FD dongles only.</li>
|
||||
<li><code>static final int TYPE_MASK_ALL</code> - search for both Dinkey Pro and FD dongles.</li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values to use as the <code>modelMask</code> parameter of <code>DinkeyChange.getDongles()</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int MODEL_MASK_LITE</code> - search for Lite dongles only.</li>
|
||||
<li><code>static final int MODEL_MASK_PLUS</code> - search for Plus dongles only.</li>
|
||||
<li><code>static final int MODEL_MASK_NET</code> - search for Net dongles only.</li>
|
||||
<li><code>static final int MODEL_MASK_ALL</code> - search for all models of dongle.</li>
|
||||
<li><code>static final int MODEL_MASK_DEFAULT</code> - search only for models that can be modified using update codes (i.e. ignore Lite dongles.)</li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values to use as the <code>model</code> parameter of <code>DinkeyChange.downloadDemoSoftwareKey()</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int SWKEY_MODEL_DEFAULT </code> - download the default model (valid only if exactly one model is set in the demo key template).</li>
|
||||
<li><code>static final int SWKEY_MODEL_PRO_LITE </code> - download a Pro Lite demo software key.</li>
|
||||
<li><code>static final int SWKEY_MODEL_PRO_PLUS</code> - download a Pro Plus demo software key.</li>
|
||||
<li><code>static final int SWKEY_MODEL_PRO_NET</code> - download a Pro Net demo software key.</li>
|
||||
<li><code>static final int SWKEY_MODEL_FD_LITE </code> - download an FD Lite demo software key.</li>
|
||||
<li><code>static final int SWKEY_MODEL_FD_PLUS</code> - download an FD Plus demo software key.</li>
|
||||
<li><code>static final int SWKEY_MODEL_FD_NET</code> - download an FD Net demo software key.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Methods</h3>
|
||||
<p>
|
||||
All methods in this class throw a <code>DinkeyChangeException</code> if the underlying native API call fails.
|
||||
The <code>DinkeyChangeException</code> contains the error code and extended error code returned by the native API function.
|
||||
</p>
|
||||
|
||||
<h4>static DongleToChange[] getDongles(int typeMask, int modelMask, String productCodeMask)</h4>
|
||||
<p>
|
||||
Returns a list of the dongles attached to this computer that match the search criteria specified by the method's arguments.
|
||||
<code>typeMask</code> and <code>modelMask</code> should be set to one of the possible values listed above.
|
||||
If <code>productCodeMask</code> is specified, only dongles with a product code that exactly matches (case is not important) this string will be returned.
|
||||
In most cases this string will be the product code of your protected application.
|
||||
Use <code>null</code> or the empty string as this parameter to search for dongles with any product code.
|
||||
</p>
|
||||
|
||||
<h4>static String writeDiagnosticsToFile(String filename)</h4>
|
||||
<p>
|
||||
Writes diagnostic information about all dongles connnected to this computer to the file specified by <code>filename</code>.
|
||||
The output file is encrypted, and its contents can only be viewed using DinkeyLook.
|
||||
The path to the file can be absolute, or relative to the current working directory.
|
||||
If the filename does not end in ".dlpf" this extension will be added automatically.
|
||||
This method returns the absolute path to the file created.
|
||||
</p>
|
||||
|
||||
<h4>static String writeDiagnosticsToFile(java.io.File file)</h4>
|
||||
<p>
|
||||
Writes diagnostic information about all dongles connnected to this computer to the file represented by <code>file</code>.
|
||||
The output file is encrypted, and its contents can only be viewed using DinkeyLook.
|
||||
The path to the file can be absolute, or relative to the current working directory.
|
||||
If the filename does not end in ".dlpf" this extension will be added automatically.
|
||||
This method returns the absolute path to the file created.
|
||||
</p>
|
||||
|
||||
<h4>static int applyUpdate(String updateCode)</h4>
|
||||
<p>
|
||||
Applies a short secure update code to a dongle connected to this computer.
|
||||
Returns the confirmation code for this update.
|
||||
</p>
|
||||
|
||||
<h4>static int applyUpdate(java.io.File updateFile)</h4>
|
||||
<p>
|
||||
Applies the secure update code in the file represented by <code>updateFile</code> to a dongle connected to this computer.
|
||||
Returns the confirmation code for this update.
|
||||
</p>
|
||||
|
||||
<h4>static void restoreDinkeyFDLite()</h4>
|
||||
<p>
|
||||
Restores the hidden <span class="filepath">.DO NOT DELETE.dat</span> on a Dinkey FD Lite dongle.
|
||||
</p>
|
||||
|
||||
<h4>static long getmachineID()</h4>
|
||||
<p>
|
||||
Returns the machine ID required to generate a temporary software key for this computer.
|
||||
</p>
|
||||
|
||||
<h4>static void downloadTempSoftwareKey()</h4>
|
||||
<p>
|
||||
Downloads and installs a temporary software key that was created by DinkeyAdd.
|
||||
</p>
|
||||
|
||||
<h4>static void downloadDemoSoftwareKey(String productCode, int model)</h4>
|
||||
<p>
|
||||
Downloads and installs a demo software key from a demo template that was created by DinkeyAdd.
|
||||
<code>productCode</code> specifies the product code of the demo template to download the key from.
|
||||
<code>model</code> specifies the model of demo key to download, and should be set to one of the values listed above.
|
||||
</p>
|
||||
|
||||
<h2>The DongleToChange Class</h2>
|
||||
<p>
|
||||
An instance of <code>DongleToChange</code> represents one dongle found by <code>DinkeyChange.getDongles()</code>.
|
||||
</p>
|
||||
|
||||
<h3>Fields</h3>
|
||||
<p>
|
||||
Possible values for <code>type</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int TYPE_PRO</code> - a Dinkey Pro dongle.</li>
|
||||
<li><code>static final int TYPE_FD</code> - a Dinkey FD dongle.</li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values for <code>mask</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int MODEL_LITE</code> - a Lite dongle.</li>
|
||||
<li><code>static final int MODEL_PLUS</code> - a Plus dongle.</li>
|
||||
<li><code>static final int MODEL_NET5</code> - a Net dongle (5 users).</li>
|
||||
<li><code>static final int MODEL_NETU</code> - a Net dongle (unlimited users).</li>
|
||||
</ul>
|
||||
<p>
|
||||
Fields that provide information needed to create an update code for this dongle:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>final int type</code> - integer representation of the dongle type.</li>
|
||||
<li><code>final String typeAsString</code> - string representation of the dongle type.</li>
|
||||
<li><code>final int model</code> - integer representation of the dongle model.</li>
|
||||
<li><code>final String modelAsString</code> - string representation of the dongle model.</li>
|
||||
<li><code>final String productCode</code> - the dongle's product code.</li>
|
||||
<li><code>final long dongleNumber</code> - the dongle's dongle number (sometimes called dongle serial number).</li>
|
||||
<li><code>final int updateNumber</code> - the dongle's update number.</li>
|
||||
</ul>
|
||||
|
||||
<h2>The DinkeyChangeException Class</h2>
|
||||
<p>
|
||||
An instance of this <code>Exception</code> subclass is thrown if a call to the DinkeyChange API fails.
|
||||
The usual <code>getMessage()</code> method returns a string providing general information about the error.
|
||||
If the problem occurred in Java code, <code>getCause()</code> will return the Java exception that caused the <code>DinkeyChangeException</code>.
|
||||
</p>
|
||||
|
||||
<h3>Methods</h3>
|
||||
<p>
|
||||
<code>DinkeyChangeException</code>'s methods provide further details about the error that occurred.
|
||||
It is strongly recommended that you display this information in the event of an error,
|
||||
to help both you and us troubleshoot a recurring problem.
|
||||
More information about Dinkey Pro/FD error numbers can be found in the user manual chapter <span class="manual">Error Codes</span>
|
||||
and online in our <a href="http://www.microcosm.co.uk/kb">knowledge base</a>.
|
||||
</p>
|
||||
<h4>int getError()</h4>
|
||||
<p>
|
||||
Returns an error code indicating the cause of the error.
|
||||
</p>
|
||||
<h4>int getExtendedError()</h4>
|
||||
<p>
|
||||
Returns an extended error code providing additional information about the error.
|
||||
</p>
|
||||
|
||||
<h2>Java Example Files</h2>
|
||||
<ul>
|
||||
<li><span class="filepath">DCSample.java</span> - various examples of using the DinkeyChange classes.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Supported Versions</h2>
|
||||
<p>
|
||||
All parts of the <code>uk.microcosm.dinkeydongle</code> package support Java platforms version 5 and newer.
|
||||
</p>
|
||||
|
||||
<h2>Try It Yourself</h2>
|
||||
<p>
|
||||
<span class="filepath">DCSample.java</span> gives a simple example of calling each of the API functions.
|
||||
To run the DCSample program you will need a copy of the appropriate shared library for your platform
|
||||
(<span class="filepath">DinkeyChange.dll</span> for 32-bit Windows, <span class="filepath">DinkeyChange64.so</span> for 64-bit Linux etc.).
|
||||
Place the library in one of the paths specified by your Java environment's <code>java.library.path</code> system property.
|
||||
Browse the examples in <code>DCSample.java</code> to see how different features can be used.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
612
Dinkey Pro 7.6.1/Samples/Java/Runtime/DPSample.java
Normal file
612
Dinkey Pro 7.6.1/Samples/Java/Runtime/DPSample.java
Normal file
@@ -0,0 +1,612 @@
|
||||
// Example use of the Dinkey Pro/FD API in Java.
|
||||
// Copyright 2018 Microcosm Ltd.
|
||||
|
||||
import uk.microcosm.dinkeydongle.DinkeyPro;
|
||||
import java.util.Arrays; // For Arrays.toString()
|
||||
|
||||
class DPSample
|
||||
{
|
||||
static final String MY_PRODCODE = "DEMO"; // !!!! Replace "DEMO" with the product code that you specify when adding protection with DinkeyAdd.
|
||||
static final int MY_SDSN = 10101; // !!!! "10101" is the SDSN used by the demo SDK and demo dongles.
|
||||
// If not using a demo, replace "10101" with your own SDSN here.
|
||||
|
||||
static final int DRIS_ENCRYPTION_PARAMETER_1 = 123; // !!!! If you enable DRIS encryption when adding protection with DinkeyAdd,
|
||||
static final int DRIS_ENCRYPTION_PARAMETER_2 = 212; // replace these values with the encryption parameters that you specify.
|
||||
static final int DRIS_ENCRYPTION_PARAMETER_3 = 97;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Each of the methods below demonstrates different API functionality.
|
||||
// Uncomment the appropriate methods to execute the examples.
|
||||
// See the comments in each method for more details about the features that they demonstrate.
|
||||
|
||||
protCheck();
|
||||
// protCheckWithAlg();
|
||||
// writeDataArea();
|
||||
// readDataArea();
|
||||
// encryptUserData();
|
||||
// protCheckEnc();
|
||||
// writeDataAreaEnc();
|
||||
// readDataAreaEnc();
|
||||
// encryptUserDataEnc();
|
||||
// displayNetUsers();
|
||||
}
|
||||
|
||||
// An example of a basic protection check
|
||||
static void protCheck()
|
||||
{
|
||||
int retCode;
|
||||
|
||||
// Create a DinkeyPro instance that uses the default library name, DPJava.
|
||||
// All DRIS fields are initialised to random values.
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
|
||||
// You can use an alternative library name like this:
|
||||
// DinkeyPro ddpro = new DinkeyPro("MyName");
|
||||
// The manner in which the library name is mapped to the actual system library is system dependent,
|
||||
// but common behaviour is that Java will attempt to locate and load MyName.dll on Windows, libMyName.dylib on macOS,
|
||||
// or libMyName.so on Linux.
|
||||
|
||||
// You can also specify the full path to the library, if it is not located in one of the paths specified by java.library.path,
|
||||
// or uses a non-standard filename:
|
||||
// Dinkey ddpro = new DinkeyPro("~/Unusual Folder For Libraries/nonstandardname.jnilib");
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.PROTECTION_CHECK;
|
||||
ddpro.flags = DinkeyPro.DEC_ONE_EXEC | DinkeyPro.START_NET_USER;
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection();
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
// You can check other values from the DRIS in other parts of your program to improve security.
|
||||
// For example:
|
||||
|
||||
// Check the SDSN
|
||||
if (ddpro.sdsn != MY_SDSN)
|
||||
{
|
||||
System.out.println("Incorrect SDSN! Have you replaced '10101' with your SDSN in the sample code?");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the product code
|
||||
if (!(ddpro.getProdCode().equals(MY_PRODCODE)))
|
||||
{
|
||||
System.out.println("Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Protection check successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that also executes an algorithm stored in the dongle.
|
||||
// The best way to use this feature is to identify lines of code in your program
|
||||
// that can be represented by algorithms stored in the dongle,
|
||||
// and replace these lines with calls to the API.
|
||||
// Lite dongle users cannot change the algorithm stored in the dongles,
|
||||
// so should calculate the algorithm in their own code and compare the result with the one returned by the API,
|
||||
// as in this example.
|
||||
static void protCheckWithAlg()
|
||||
{
|
||||
int retCode;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.EXECUTE_ALGORITHM;
|
||||
ddpro.flags = 0;
|
||||
ddpro.alg_number = 1; // The algorithm to execute. Lite dongles ignore this field, as they contain only 1 algorithm
|
||||
ddpro.var_a = 1; // The input variables to use in the algorithm
|
||||
ddpro.var_b = 2;
|
||||
ddpro.var_c = 3;
|
||||
ddpro.var_d = 4;
|
||||
ddpro.var_e = 5;
|
||||
ddpro.var_f = 6;
|
||||
ddpro.var_g = 7;
|
||||
ddpro.var_h = 8;
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection();
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
// Check the algorithm result in another part of your program to improve security.
|
||||
// !!!! Ensure the myAlgorithm() method matches the algorithm that was executed by the protection check!
|
||||
if (myAlgorithm(ddpro.var_a, ddpro.var_b, ddpro.var_c, ddpro.var_d, ddpro.var_e, ddpro.var_f, ddpro.var_g, ddpro.var_h) != ddpro.alg_answer)
|
||||
{
|
||||
System.out.println("Error! The algorithm result was not as expected.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Protection check with algorithm successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that also writes data to the dongle's secure data area.
|
||||
// This feature is not supported by Lite dongles.
|
||||
// Make sure you specify a large enough data area size when adding protection with DinkeyAdd!
|
||||
static void writeDataArea()
|
||||
{
|
||||
int retCode;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // Data to write
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.WRITE_DATA_AREA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_offset = 0; // Index to start writing at. Indices start at zero
|
||||
ddpro.rw_length = data.length; // The number of bytes to be written
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// You can inspect the dongle with DinkeyLook to see that the data has been written to the dongle
|
||||
|
||||
System.out.println("Writing data successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that also reads data from the dongle's secure data area.
|
||||
// This feature is not supported by Lite dongles.
|
||||
// Make sure you specify a large enough data area size when adding protection with DinkeyAdd!
|
||||
static void readDataArea()
|
||||
{
|
||||
int retCode;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = new byte[10];
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.READ_DATA_AREA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_offset = 0; // Index to start reading from. Indices start at zero
|
||||
ddpro.rw_length = data.length; // The number of bytes to read
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Reading data successful: " + Arrays.toString(data));
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of protection checks that encrypt/decrypt your data.
|
||||
// This feature is not supported by Lite dongles.
|
||||
static void encryptUserData()
|
||||
{
|
||||
int retCode;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // The data to be encrypted
|
||||
byte[] originalData = data.clone(); // A copy of the data for displaying later
|
||||
byte[] encryptedData;
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.ENCRYPT_USER_DATA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_length = data.length; // The number of bytes to be encrypted
|
||||
ddpro.data_crypt_key_num = 1; // The encryption key to use
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
encryptedData = data.clone(); // A copy of the encrypted data for displaying later
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.reset(); // Reset the DRIS fields with random values
|
||||
ddpro.function = DinkeyPro.DECRYPT_USER_DATA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_length = data.length;
|
||||
ddpro.data_crypt_key_num = 1; // This must be the same key used to encrypt the data
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Data encryption successful.");
|
||||
System.out.println("Original data: " + Arrays.toString(originalData));
|
||||
System.out.println("Encrypted data: " + Arrays.toString(encryptedData));
|
||||
System.out.println("Decrypted data: " + Arrays.toString(data));
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that uses DRIS encryption for extra security.
|
||||
static void protCheckEnc()
|
||||
{
|
||||
int retCode;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.PROTECTION_CHECK;
|
||||
ddpro.flags = 0;
|
||||
|
||||
// Encrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection();
|
||||
|
||||
// Decrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
// You can check other values from the DRIS in other parts of your program to improve security.
|
||||
// For example:
|
||||
|
||||
// Check the SDSN
|
||||
if (ddpro.sdsn != MY_SDSN)
|
||||
{
|
||||
System.out.println("Incorrect SDSN! Have you replaced '10101' with your SDSN in the sample code?");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the product code
|
||||
if (!(ddpro.getProdCode().equals(MY_PRODCODE)))
|
||||
{
|
||||
System.out.println("Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Protection check successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that also writes data to the dongle's secure data area.
|
||||
// This feature is not supported by Lite dongles.
|
||||
// Make sure you specify a large enough data area size when adding protection with DinkeyAdd!
|
||||
// This method also uses DRIS encryption and data encryption for extra security.
|
||||
// You must select these options on the Extra Security tab of DinkeyAdd for this method to work correctly!
|
||||
static void writeDataAreaEnc()
|
||||
{
|
||||
int retCode, algAnswer;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // The data to be written
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.WRITE_DATA_AREA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_offset = 0; // Index to start writing at. Indices start at zero
|
||||
ddpro.rw_length = data.length; // The number of bytes to write
|
||||
|
||||
// If taking data encryption parameters from the R/W algorithm:
|
||||
// Calculate the R/W algorithm result
|
||||
// The input variables were initialised to random values when ddpro was created
|
||||
algAnswer = myRwAlgorithm(ddpro.var_a, ddpro.var_b, ddpro.var_c, ddpro.var_d, ddpro.var_e, ddpro.var_f, ddpro.var_g, ddpro.var_h);
|
||||
|
||||
// Use the algorithm result to encrypt the data to be written to the dongle
|
||||
ddpro.cryptApiData(data, algAnswer);
|
||||
|
||||
// If using constant data encryption parameters:
|
||||
// ddpro.cryptApiData(data, DATA_ENCRYPTION_PARAMETER_1, DATA_ENCRYPTION_PARAMETER_2, DATA_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Encrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Decrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Writing data successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a protection check that also reads data from the dongle's secure data area.
|
||||
// This feature is not supported by Lite dongles.
|
||||
// Make sure you specify a large enough data area size when adding protection with DinkeyAdd!
|
||||
// This method also uses DRIS encryption and data encryption for extra security.
|
||||
// You must select these options on the Extra Security tab of DinkeyAdd for this method to work correctly!
|
||||
static void readDataAreaEnc()
|
||||
{
|
||||
int retCode, algAnswer;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = new byte[10];
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.READ_DATA_AREA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_offset = 0; // Index to start reading from. Indices start at zero
|
||||
ddpro.rw_length = data.length; // The number of bytes to read
|
||||
|
||||
// Encrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Decrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// If taking data encryption parameters from the R/W algorithm:
|
||||
// Calculate the R/W algorithm result
|
||||
// The input variables were initialised to random values when ddpro was created
|
||||
algAnswer = myRwAlgorithm(ddpro.var_a, ddpro.var_b, ddpro.var_c, ddpro.var_d, ddpro.var_e, ddpro.var_f, ddpro.var_g, ddpro.var_h);
|
||||
|
||||
// Use the algorithm result to decrypt the data read from the dongle
|
||||
ddpro.cryptApiData(data, algAnswer);
|
||||
|
||||
// If using constant data encryption parameters:
|
||||
// ddpro.cryptApiData(data, DATA_ENCRYPTION_PARAMETER_1, DATA_ENCRYPTION_PARAMETER_2, DATA_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
System.out.println("Reading data successful: " + Arrays.toString(data));
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of protection checks that encrypt/decrypt your data.
|
||||
// This feature is not supported by Lite dongles.
|
||||
// This method also uses DRIS encryption and data encryption for extra security.
|
||||
// You must select these options on the Extra Security tab of DinkeyAdd for this method to work correctly!
|
||||
static void encryptUserDataEnc()
|
||||
{
|
||||
int retCode, algAnswer;
|
||||
DinkeyPro ddpro = new DinkeyPro();
|
||||
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // The data to be encrypted
|
||||
byte[] originalData = data.clone(); // A copy of the data for displaying later
|
||||
byte[] encryptedData;
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.ENCRYPT_USER_DATA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_length = data.length; // The number of bytes to be encrypted
|
||||
ddpro.data_crypt_key_num = 1; // The encryption key to use
|
||||
|
||||
// If taking data encryption parameters from the R/W algorithm:
|
||||
// Calculate the R/W algorithm result
|
||||
// The input variables were initialised to random values when ddpro was created
|
||||
algAnswer = myRwAlgorithm(ddpro.var_a, ddpro.var_b, ddpro.var_c, ddpro.var_d, ddpro.var_e, ddpro.var_f, ddpro.var_g, ddpro.var_h);
|
||||
|
||||
// Use the algorithm result to encrypt the data passed to the API
|
||||
ddpro.cryptApiData(data, algAnswer);
|
||||
|
||||
// If using constant data encryption parameters:
|
||||
// ddpro.cryptApiData(data, DATA_ENCRYPTION_PARAMETER_1, DATA_ENCRYPTION_PARAMETER_2, DATA_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Encrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Decrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Do not call cryptApiData() here to decrypt the data received from the API!
|
||||
// The data has been encrypted by the dongle hardware, so the API will not apply an unnecessary second layer of encryption
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
encryptedData = data.clone(); // A copy of the encrypted data for displaying later
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.reset(); // Reset the DRIS fields with random values
|
||||
ddpro.function = DinkeyPro.DECRYPT_USER_DATA;
|
||||
ddpro.flags = DinkeyPro.USE_FUNCTION_ARGUMENT; // Java uses DDProtCheck()'s data parameter, so this flag must be set
|
||||
ddpro.rw_length = data.length;
|
||||
ddpro.data_crypt_key_num = 1; // This must be the same key used to encrypt the data
|
||||
|
||||
// Encrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Do not call cryptApiData() here to encrypt the data passed to the API!
|
||||
// The data is already encrypted, so the API does not expect an unnecessary second layer of encryption
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection(data);
|
||||
|
||||
// Decrypt the DRIS
|
||||
ddpro.cryptDris(DRIS_ENCRYPTION_PARAMETER_1, DRIS_ENCRYPTION_PARAMETER_2, DRIS_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// If taking data encryption parameters from the R/W algorithm:
|
||||
// Calculate the R/W algorithm result
|
||||
// The input variables were initialised to random values when ddpro was created
|
||||
algAnswer = myRwAlgorithm(ddpro.var_a, ddpro.var_b, ddpro.var_c, ddpro.var_d, ddpro.var_e, ddpro.var_f, ddpro.var_g, ddpro.var_h);
|
||||
|
||||
// Use the algorithm result to decrypt the data received from the API
|
||||
ddpro.cryptApiData(data, algAnswer);
|
||||
|
||||
// If using constant data encryption parameters:
|
||||
// ddpro.cryptApiData(data, DATA_ENCRYPTION_PARAMETER_1, DATA_ENCRYPTION_PARAMETER_2, DATA_ENCRYPTION_PARAMETER_3);
|
||||
|
||||
System.out.println("Data encryption successful.");
|
||||
System.out.println("Original data: " + Arrays.toString(originalData));
|
||||
System.out.println("Encrypted data: " + Arrays.toString(encryptedData));
|
||||
System.out.println("Decrypted data: " + Arrays.toString(data));
|
||||
return;
|
||||
}
|
||||
|
||||
// An example of a simple protection check and displaying information about the current users of a network dongle.
|
||||
// This feature is supported by Dinkey Pro Net and Dinkey FD Net dongles only.
|
||||
// queryNetUsers() will only work following a call to checkProtection() that established a connection to DinkeyServer.
|
||||
static void displayNetUsers()
|
||||
{
|
||||
int retCode, maxNetUsersToQuery;
|
||||
|
||||
DinkeyPro ddpro = new DinkeyPro(); // Create a DinkeyPro instance. All DRIS fields are initialised to random values
|
||||
|
||||
// Initialise the DRIS
|
||||
ddpro.function = DinkeyPro.PROTECTION_CHECK;
|
||||
ddpro.flags = DinkeyPro.START_NET_USER;
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.checkProtection();
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
displayError(retCode, ddpro.ext_err);
|
||||
return;
|
||||
}
|
||||
|
||||
// If you lock your software to multiple dongle models,
|
||||
// you might want to check that a network dongle was found before trying to get network user information
|
||||
if ((ddpro.model == DinkeyPro.MODEL_LITE) || (ddpro.model == DinkeyPro.MODEL_PLUS))
|
||||
{
|
||||
System.out.println("Local dongle found. No network user information to display.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set maxNetUsersToQuery to a sensible value!
|
||||
// This example requests information about 10 users if there is no limit to the number of users supported by the dongle
|
||||
if (ddpro.net_users == DinkeyPro.UNLIMITED_NET_USERS)
|
||||
maxNetUsersToQuery = 10;
|
||||
else
|
||||
maxNetUsersToQuery = ddpro.net_users;
|
||||
|
||||
// Call the API
|
||||
retCode = ddpro.queryNetUsers(maxNetUsersToQuery);
|
||||
|
||||
// Check the return value
|
||||
if (retCode != 0)
|
||||
{
|
||||
System.out.println("An error occurred getting network user information.");
|
||||
System.out.println("Error: " + retCode + "\nExtended Error: " + ddpro.queryNetUsersExtErr);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(ddpro.numNetUsers + " current network users:\n");
|
||||
for (int i = 0; i < ddpro.num_net_users; i++)
|
||||
{
|
||||
System.out.println((i+1) + ") " + ddpro.userNames[i] + " @ " + ddpro.computerNames[i] + " (" + ddpro.ipAddresses[i] + ") using licence '" + ddpro.licenceNames[i] + "'");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// !!!! This method must match one stored in the dongle for protCheckWithAlg() to work correctly.
|
||||
// For Lite dongles, use DinkeyLook to see the algorithm pre-programmed into the dongle.
|
||||
// For Plus and Net dongles, ensure this algorithm matches one you specified in DinkeyAdd when adding protection.
|
||||
static int myAlgorithm(int a, int b, int c, int d, int e, int f, int g, int h)
|
||||
{
|
||||
return a + b + c + d + e + f + g + h;
|
||||
}
|
||||
|
||||
// !!!! This method must match the R/W algorithm stored in the dongle for
|
||||
// writeDataAreaEnc() and readDataAreaEnc() to work correctly.
|
||||
static int myRwAlgorithm(int a, int b, int c, int d, int e, int f, int g, int h)
|
||||
{
|
||||
return a ^ b ^ c ^ d ^ e ^ f;
|
||||
}
|
||||
|
||||
|
||||
// An example of error reporting. Displays descriptions for some common error codes.
|
||||
// IMPORTANT - THE MESSAGES DISPLAYED ARE TO HELP DEVELOPERS IMPLEMENT THE DINKEY PRO/FD API.
|
||||
// THEY ARE NOT SUITABLE FOR DISPLAYING TO USERS!
|
||||
static void displayError(int retCode, int extErr)
|
||||
{
|
||||
switch (retCode)
|
||||
{
|
||||
case 401:
|
||||
System.out.println("Error! No dongles detected!");
|
||||
break;
|
||||
case 403:
|
||||
System.out.println("Error! The dongle is a different type to the one specified in DinkeyAdd.");
|
||||
break;
|
||||
case 404:
|
||||
System.out.println("Error! The dongle is a different model to those specified in DinkeyAdd.");
|
||||
break;
|
||||
case 409:
|
||||
System.out.println("Error! The dongle has not been programmed by DinkeyAdd.");
|
||||
break;
|
||||
case 410:
|
||||
System.out.println("Error! The dongle has a different product code to the one specified in DinkeyAdd.");
|
||||
break;
|
||||
case 411:
|
||||
System.out.println("Error! This software's licence was not found in the dongle.");
|
||||
break;
|
||||
case 413:
|
||||
System.out.println("Error! This software has not been locked by DinkeyAdd. For guidance please read the DinkeyAdd chapter of the user manual.");
|
||||
break;
|
||||
case 417:
|
||||
System.out.println("Error! One or more of the parameters set in the DRIS is incorrect.\nCheck if you are encrypting the DRIS in your code but did not specify DRIS encryption in DinkeyAdd - or vice versa.");
|
||||
break;
|
||||
case 423:
|
||||
System.out.println("Error! The number of network users has been exceeded.");
|
||||
break;
|
||||
case 435:
|
||||
System.out.println("Error! DinkeyServer has not been detected on the network.");
|
||||
break;
|
||||
case 922:
|
||||
System.out.println("Error! The Software Key has expired.");
|
||||
break;
|
||||
default:
|
||||
System.out.println("An error occurred checking the dongle.\nError: " + retCode + "\nExtended Error: " + extErr);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
438
Dinkey Pro 7.6.1/Samples/Java/Runtime/README.html
Normal file
438
Dinkey Pro 7.6.1/Samples/Java/Runtime/README.html
Normal file
@@ -0,0 +1,438 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Using Dinkey Pro/FD with Java</title>
|
||||
<style>
|
||||
body {
|
||||
color: black;
|
||||
font-family: Verdana, Arial, Helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
margin: 25px auto;
|
||||
max-width: 800px;
|
||||
}
|
||||
p, ul, ol, table {
|
||||
margin-top: 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
ul.contents a {
|
||||
text-decoration: none;
|
||||
}
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
margin-top: 25px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
h2 {
|
||||
border-top: 1px solid gray;
|
||||
}
|
||||
table {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid black;
|
||||
padding: 0.5em;
|
||||
text-align: left;
|
||||
}
|
||||
.ui_element
|
||||
{ /* Use for things like program options and menu items */
|
||||
color: #008000;
|
||||
font-style: italic;
|
||||
}
|
||||
.filepath
|
||||
{ /* Use for paths and filenames */
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.manual
|
||||
{ /* Use when referring to user manual sections/chapters */
|
||||
font-style: italic;
|
||||
}
|
||||
.alert
|
||||
{
|
||||
border: 1px solid black;
|
||||
padding: 15px 15px 15px 58px;
|
||||
font-weight: bold;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 5px 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.important
|
||||
{
|
||||
background-color: #FFFDD0;
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH2wcJCS0n8fQB3QAACsBJREFUaIHtmWmMHMUVx3/Vx/Tc6/Xa61l717sEY/BibA4bAQIiOzGHIoMUiURgwEEEBYkoBESsSAGJBIFIEIQoARwlEBnJQTJBAhMDPggECQewYyPjSPgCG+ODXa/3mJ2e7pnuqnyY6Z6e3dkDDFE+8KSn6umpfv3/v/eq6lU1fC1fyymJ+LIMKRDPQbeCbxvwTaBbQguQrHaxdfhMwX88eB14YwXsO9X3njKBv0DOgh8L+KEByVwyaUzJZhNpy8IyTXQAKfE8D8d1GXZd+goF+0S57Ptw0oc/Cli9Avr/pwTWwVQfHlZwY3smo3W0tVnZlhZwXRgcRNg2ynURvg9KgaaBYYBpoiwLpRQD+TyHhoaKPZ6nFPzBg1/dDIWvnMBauE7An2dls7HT58yJx1Mp5OHDcPw4wnURgBYxHrQqotI0IZVCJRLYjsO+wUH7hO8XJNywArZ8JQTWgS5hta5p1y8866zUlFwOuW8f6uhRNCnRqsAD8IEGUkcgUCFQVSJ9hQK7CwVbwm+vh/tEpeuXQ+AVsIbg79l4/JIFF16Y1AsF/N270UqlOuB6Oo22bBli0SJEayuivR0MAzUwAAcOoLZuRW3ejCwWayQAX9chk8HxfXbl84WiUi/pcPP3wD9lAutA92FjSyp1yfxLL03IAweQBw5UAAfAFy/GuOcetCVLEPE4QlRMB61SKmyVbSM3b0Y+8ghy1y78CBGZTOLrOh/k84UhpZ5fAbecMoHn4KnmROLG+ZddlvY//BB1+HAIXu/oIPbgg+jLlyM0DSEEmqbV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qG6bSeATiEU10wpT74JnmZPKs9sWL43JwkMLu3SjPG0VEAFo2i9nZichmAZADA3iHDiGHh0PQUfBC09AyGXyl6M3niyeV2vYzuNuugHeq4J2ITkjAonIOExJpgcwv4cFmTbtsVnd3PDltGvaePZSOH0dUB+XIbwKNJAoeIdCSSbRkEse2OVEouEfhpV/A77wa+KgGUQAmHgN1B9BFUK/AP09XaiDR07OoNDBApqtLT3R1VcrfYrFWtDHay9HNiTIM9EwGvbkZH+gbHCwNuW7xLXjoN7BOVkCWgPKI1iMykCc63LWoRcCKtgsgdyvcORUuyzQ1aU25nGFNnYq0bbzBQaRtI123cqKnVOXk2jAQpomwLISm4eTz5PP5slMuy09h01Pwp08q38rcqrdHtsF1KJM5Xo8CDzQWtJdD53fg+21whRBCS6dSsXgmY5iWhW6aCEBJifQ8PNel7LoUbbvsuK7ng3sYNj4Pf9tVqfMDr0fbQEeBnywBqOwb4lXggVqAWb02ExC7BuZ3w+JWOC8OHTpkReV/JaHsw0ARDh+F7bvg36/CPq+WFtFUCQgE6tDgZPrzEAjEHAm8Si5o9Wo78nNZIHWfx6qg/AiBRkTKjCNf9DOrVgUdAA9UpzboR36sjBII2uB7hhfRclXrVtwvm8BI0WhMYKIPlVECkwL8tfy/yX8BjYmrtt9ODsIAAAAASUVORK5CYII=');
|
||||
}
|
||||
.information
|
||||
{
|
||||
background-color: #EBF8FF;
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAYdEVYdFRpdGxlAERpYWxvZyBJbmZvcm1hdGlvbvUv0PgAAAAUdEVYdEF1dGhvcgBKYWt1YiBTdGVpbmVy5vv3LwAAACF0RVh0U291cmNlAGh0dHA6Ly9qaW1tYWMubXVzaWNoYWxsLmN6aWbjXgAACnJJREFUaI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Hckus1QW4YYJn4pcLbFgFItW37rpH3b9i44cHhwb5UNuVQqxtMTBYa0zOzT589dfJgS3R9ybVtVwi/HsRq5gFaZrzULpw780y6I7PvzLnGnWEYuEaSWNdIXrg0fv77Lfh22+X3WZmIFYbQ8rBZ/kRCNJ9E2LIgk8l0924cuGNudnq0trBQxq97OGlZ3LIGXtn7S8fCVf/4W/Fyunlg8rLgtrXfM67sXbuk3i7SMrek7pdc3bK602uIXNV+oDUu2hB8FQNeGRqtA5YrYHQZhL9e9lkTgFfcrPl02mKXxvfy0oZoi9Rr9fK1yv8BQhlE2oxknwEAAAAASUVORK5CYII=');
|
||||
}
|
||||
.alert > p:last-child, .alert > ul:last-child, .alert > ol:last-child
|
||||
{
|
||||
/* Cancel double space at bottom of alert caused by above rule */
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.important .filepath, .information .filepath {
|
||||
/* Make filepaths stand out in sections that are already bold */
|
||||
font-weight: normal;
|
||||
}
|
||||
div.col_wrapper
|
||||
{
|
||||
clear: both;
|
||||
overflow: hidden;
|
||||
}
|
||||
div.two_col
|
||||
{
|
||||
width: 50%;
|
||||
float: left;
|
||||
}
|
||||
code {
|
||||
color: gray;
|
||||
white-space: nowrap;
|
||||
}
|
||||
pre {
|
||||
padding: 15px;
|
||||
background-color: #EEEEEE;
|
||||
}
|
||||
pre > code { /* Block level code snippets */
|
||||
white-space: pre; /* Override nowrap used for inline code */
|
||||
color: inherit;
|
||||
}
|
||||
code .comment
|
||||
{
|
||||
color: green;
|
||||
}
|
||||
code .keyword
|
||||
{
|
||||
font-weight: bold;
|
||||
color: blue;
|
||||
}
|
||||
code .string
|
||||
{
|
||||
color: #A00000;
|
||||
}
|
||||
code .constant
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Using Dinkey Pro/FD with Java</h1>
|
||||
<div class="alert information">
|
||||
<p>
|
||||
Protection checks in Java are implemented using <span class="filepath">DinkeyPro.class</span> to communicate with the dongle via the appropriate native library
|
||||
(<span class="filepath">DPJava.dll</span> on 32-bit Windows, <span class="filepath">libDPJava64.so</span> on 64-bit Linux, etc.).
|
||||
You should lock these native libraries with the API method using DinkeyAdd as described in the user manual, and distribute the locked libraries with your software.
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
The <code>DinkeyPro</code> class provides a Java wrapper around the Dinkey Pro/FD API, which is implemented by native libraries.
|
||||
If you are not familiar with calling native libraries, it is recommended that you read the Java documentation on the subject,
|
||||
especially the documentation for <code>System.loadLibrary()</code> and <code>System.load()</code>,
|
||||
and how Java uses the system property <code>java.library.path</code> to locate native libraries.
|
||||
</p>
|
||||
<p>
|
||||
The native libraries and the <code>DinkeyPro</code> class are part of the <code>uk.microcosm.dinkeydongle</code> package.
|
||||
See the documentation for your development environment for details of how to include and reference this package in your project.
|
||||
<span class="filepath">dinkeydongle.jar</span> provides all of the Java classes in the <code>uk.microcosm.dinkeydongle</code> package in a single JAR file.
|
||||
This allows you to import the package much more easily in many Java IDEs. Note that the native libraries are <strong>not</strong> included in the JAR file.
|
||||
You will need to distribute with your software locked copies of the native libraries for every platform that your software supports.
|
||||
</p>
|
||||
<p>
|
||||
Do not specify a <em>calling program</em> when locking the native libraries.
|
||||
The calling program for Java software is the user's JVM, which will be different for different users.
|
||||
</p>
|
||||
<p>
|
||||
Java bytecode is more easily decompiled than native code.
|
||||
For maximum security, it is recommended that you obfuscate your Java code using a third-party tool.
|
||||
</p>
|
||||
|
||||
<h2>The DinkeyPro Class</h2>
|
||||
<p>
|
||||
Instances of <code>DinkeyPro</code> contain an internal DRIS.
|
||||
Most of this structure's members are exposed as public fields that can be directly accessed.
|
||||
Others must be accessed via <code>get...()</code> and <code>set...()</code> methods: see below for details.
|
||||
As Java does not have unsigned types, DRIS members that are documented as unsigned integers in the user manual
|
||||
are represented by <code>long</code> fields in the <code>DinkeyPro</code> class.
|
||||
</p>
|
||||
<div class="alert information">
|
||||
<p>
|
||||
The <code>header</code> and <code>size</code> DRIS members are set automatically.
|
||||
You do not need to set these fields in your code.
|
||||
</p>
|
||||
<p>
|
||||
<code>rw_data_ptr</code> is not used in Java. To use an API function that passes data to/from the dongle,
|
||||
you must use the <code>checkProtection(byte[] data)</code> method and also set the <code>USE_FUNCTION_ARGUMENT</code> flag.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3>Fields</h3>
|
||||
<p>
|
||||
Possible values for the <code>function</code> DRIS field, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int PROTECTION_CHECK</code></li>
|
||||
<li><code>static final int EXECUTE_ALGORITHM</code></li>
|
||||
<li><code>static final int WRITE_DATA_AREA</code></li>
|
||||
<li><code>static final int READ_DATA_AREA</code></li>
|
||||
<li><code>static final int ENCRYPT_USER_DATA</code></li>
|
||||
<li><code>static final int DECRYPT_USER_DATA</code></li>
|
||||
<li><code>static final int FAST_PRESENCE_CHECK</code></li>
|
||||
<li><code>static final int STOP_NET_USER</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values for the <code>flags</code> DRIS field, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int DEC_ONE_EXEC</code></li>
|
||||
<li><code>static final int DEC_MANY_EXECS</code></li>
|
||||
<li><code>static final int START_NET_USER</code></li>
|
||||
<li><code>static final int USE_FUNCTION_ARGUMENT</code></li>
|
||||
<li><code>static final int CHECK_LOCAL_FIRST</code></li>
|
||||
<li><code>static final int CHECK_NETWORK_FIRST</code></li>
|
||||
<li><code>static final int USE_ALT_LICENCE_NAME</code></li>
|
||||
<li><code>static final int DONT_SET_MAXDAYS_EXPIRY</code></li>
|
||||
<li><code>static final int MATCH_DONGLE_NUMBER</code></li>
|
||||
<li><code>static final int DONT_RETURN_FD_DRIVE</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values for the <code>type</code> DRIS field, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int TYPE_PRO</code></li>
|
||||
<li><code>static final int TYPE_FD</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values for the <code>model</code> DRIS field, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int MODEL_LITE</code></li>
|
||||
<li><code>static final int MODEL_PLUS</code></li>
|
||||
<li><code>static final int MODEL_NET5</code></li>
|
||||
<li><code>static final int MODEL_NETU</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Possible values for the <code>net_users</code> DRIS field, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>static final int UNLIMITED_NET_USERS</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Directly accessible DRIS fields, as documented in the user manual:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>int seed1</code></li>
|
||||
<li><code>int seed2</code></li>
|
||||
<li><code>int function</code></li>
|
||||
<li><code>int flags</code></li>
|
||||
<li><code>long execs_decrement</code></li>
|
||||
<li><code>int data_crypt_key_num</code></li>
|
||||
<li><code>int rw_offset</code></li>
|
||||
<li><code>int rw_length</code></li>
|
||||
<li><code>int var_a</code></li>
|
||||
<li><code>int var_b</code></li>
|
||||
<li><code>int var_c</code></li>
|
||||
<li><code>int var_d</code></li>
|
||||
<li><code>int var_e</code></li>
|
||||
<li><code>int var_f</code></li>
|
||||
<li><code>int var_g</code></li>
|
||||
<li><code>int var_h</code></li>
|
||||
<li><code>int alg_number</code></li>
|
||||
<li><code>int ret_code</code></li>
|
||||
<li><code>int ext_err</code></li>
|
||||
<li><code>int type</code></li>
|
||||
<li><code>int model</code></li>
|
||||
<li><code>int sdsn</code></li>
|
||||
<li><code>long dongle_number</code></li>
|
||||
<li><code>int update_number</code></li>
|
||||
<li><code>long data_area_size</code></li>
|
||||
<li><code>int max_alg_num</code></li>
|
||||
<li><code>int execs</code></li>
|
||||
<li><code>int exp_day</code></li>
|
||||
<li><code>int exp_month</code></li>
|
||||
<li><code>int exp_year</code></li>
|
||||
<li><code>long features</code></li>
|
||||
<li><code>int net_users</code></li>
|
||||
<li><code>int alg_answer</code></li>
|
||||
<li><code>long fd_capacity</code></li>
|
||||
<li><code>int swkey_type</code></li>
|
||||
<li><code>int swkey_exp_day</code></li>
|
||||
<li><code>int swkey_exp_month</code></li>
|
||||
<li><code>int swkey_exp_year</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
Fields used to access information returned by <code>DDGetNetUserList()</code>:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>int numNetUsers</code> - the current number of network users when <code>DDGetNetUserList()</code> was called.</li>
|
||||
<li><code>int queryNetUsersExtErr</code> - contains additional error information if <code>DDGetNetUserList()</code> returns failure.</li>
|
||||
<li><code>String[] licenceNames</code> - the names of the licences currently used by network users.</li>
|
||||
<li><code>String[] userNames</code> - the usernames of the current network users.</li>
|
||||
<li><code>String[] computerNames</code> - the computer names of the current network users.</li>
|
||||
<li><code>String[] ipAddresses</code> - the IP addresses of the current network users.</li>
|
||||
</ul>
|
||||
<p>
|
||||
The string arrays should be used in combination, i.e. <code>licenceNames[0]</code>, <code>userNames[0]</code>,
|
||||
<code>computerNames[0]</code> and <code>ipAddresses[0]</code> together describe a single network user.
|
||||
</p>
|
||||
|
||||
<h3>Constructors</h3>
|
||||
<p>
|
||||
These constructors can throw any exception thrown by <code>System.loadLibrary()</code> and <code>System.load()</code>.
|
||||
See the documentation for those methods for details.
|
||||
</p>
|
||||
|
||||
<h4>DinkeyPro()</h4>
|
||||
<p>
|
||||
Creates a new DinkeyPro instance and calls <code>System.loadLibrary()</code>
|
||||
to load the native library using the default filename.
|
||||
The library must be located in one of the paths specified in the <code>java.library.path</code> system property.
|
||||
The exact filename is implementation-dependent, but the most common names are:
|
||||
</p>
|
||||
<ul>
|
||||
<li>32-bit Windows - <span class="filepath">DPJava.dll</span></li>
|
||||
<li>64-bit Windows - <span class="filepath">DPJava64.dll</span></li>
|
||||
<li>32-bit Linux - <span class="filepath">libDPJava.so</span></li>
|
||||
<li>64-bit Linux - <span class="filepath">libDPJava64.so</span></li>
|
||||
<li>64-bit macOS - <span class="filepath">libDPJava64.dylib</span></li>
|
||||
</ul>
|
||||
<p>
|
||||
The members of the instance's internal DRIS are initialised to random values.
|
||||
</p>
|
||||
|
||||
<h4>DinkeyPro(String libName)</h4>
|
||||
<p>
|
||||
Creates a new DinkeyPro instance and calls <code>System.loadLibrary(libName)</code> to load the native library.
|
||||
The library must be located in one of the paths specified in the <code>java.library.path</code> system property.
|
||||
If <code>System.loadLibrary(libName)</code> fails, it then calls <code>System.load(libName)</code>.
|
||||
Use this version of the constructor if you rename the native libraries (recommended), or if you need to specify the absolute
|
||||
path to the library.
|
||||
</p>
|
||||
<p>
|
||||
The members of the instance's internal DRIS are initialised to random values.
|
||||
</p>
|
||||
|
||||
<h3>Methods</h3>
|
||||
|
||||
<h4>int checkProtection()</h4>
|
||||
<p>
|
||||
Calls <code>DDProtCheck()</code> in the native library using the internal DRIS.
|
||||
Returns zero on success, or a value indicating the cause of the error on failure.
|
||||
</p>
|
||||
|
||||
<h4>int checkProtection(byte[] data)</h4>
|
||||
<p>
|
||||
Calls <code>DDProtCheck()</code> in the native library using the internal DRIS.
|
||||
<code>data</code> is passed to the API (e.g. when writing to the dongle data area),
|
||||
or acts as a buffer filled by the API (e.g. when reading from the dongle data area).
|
||||
When using this method you must also set the <code>USE_FUNCTION_ARGUMENT</code> flag.
|
||||
Returns zero on success, or a value indicating the cause of the error on failure.
|
||||
</p>
|
||||
|
||||
<h4>int queryNetUsers(int maxUsersToQuery)</h4>
|
||||
<p>
|
||||
Calls <code>DDGetNetUserList()</code> in the native library.
|
||||
<code>maxNetUsersToQuery</code> specifies the maximum number of current network users to return information about.
|
||||
Use this version of this method to get information about the current network users for the protected software's licence
|
||||
(if protected with the <em>per licence</em> network users option), or all licences in the dongle
|
||||
(if protected with the <em>per product</em> network users option).
|
||||
Returns zero on success, or a value indicating the cause of the error on failure.
|
||||
</p>
|
||||
|
||||
<h4>int queryNetUsers(String licenceName, int maxUsersToQuery)</h4>
|
||||
<p>
|
||||
Calls <code>DDGetNetUserList()</code> in the native library.
|
||||
<code>maxNetUsersToQuery</code> specifies the maximum number of current network users to return information about.
|
||||
Use this version of this method to get information about the current network users for the licence specified by <code>licenceName</code>.
|
||||
Returns zero on success, or a value indicating the cause of the error on failure.
|
||||
</p>
|
||||
|
||||
<h4>void reset()</h4>
|
||||
<p>
|
||||
Set all members of the internal DRIS to random values.
|
||||
</p>
|
||||
|
||||
<h4>String getProdCode()</h4>
|
||||
<p>
|
||||
Return the <code>prodcode</code> member of the internal DRIS as a Java string.
|
||||
</p>
|
||||
|
||||
<h4>String getFdDrive()</h4>
|
||||
<p>
|
||||
Return the <code>fd_drive</code> member of the internal DRIS as a Java string.
|
||||
</p>
|
||||
|
||||
<h4>void setAltLicenceName(String altLicenceName)</h4>
|
||||
<p>
|
||||
Assign the value of <code>altLicenceName</code> to the <code>alt_licence_name</code> member of the internal DRIS.
|
||||
</p>
|
||||
|
||||
<h4>void cryptDris(int encryptionParameter1, int encryptionParameter2, int encryptionParameter3)</h4>
|
||||
<p>
|
||||
Encrypt/decrypt the internal DRIS.
|
||||
<code>encryptionParameter1</code>, <code>encryptionParameter2</code> and <code>encryptionParameter3</code>
|
||||
must match the parameters specified for DRIS encryption in DinkeyAdd.
|
||||
</p>
|
||||
|
||||
<h4>void cryptApiData(byte[] data, int algAnswer)</h4>
|
||||
<p>
|
||||
Encrypt/decrypt <code>checkProtection()</code>'s <code>data</code> parameter using the result of the R/W algorithm.
|
||||
The option to take data encryption parameters from the R/W algorithm must also be selected in DinkeyAdd when adding protection,
|
||||
and <code>algAnswer</code> must be the result of an algorithm that matches the R/W algorithm specified there.
|
||||
</p>
|
||||
|
||||
<h4>void cryptApiData(byte[] data, int encryptionParameter1, int encryptionParameter2, int encryptionParameter3)</h4>
|
||||
<p>
|
||||
Encrypt/decrypt <code>checkProtection()</code>'s <code>data</code> parameter using constant parameters.
|
||||
The option to use constant data encryption parameters must be selected in DinkeyAdd when adding protection, and
|
||||
<code>encryptionParameter1</code>, <code>encryptionParameter2</code> and <code>encryptionParameter3</code>
|
||||
must match the parameters specified there.
|
||||
</p>
|
||||
|
||||
<h2>Java Example Files</h2>
|
||||
<ul>
|
||||
<li><span class="filepath">DPSample.java</span> - various examples of using the <code>DinkeyPro</code> class.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Supported Versions</h2>
|
||||
<p>
|
||||
All parts of the <code>uk.microcosm.dinkeydongle</code> package support Java platforms version 5 and newer.
|
||||
</p>
|
||||
|
||||
<h2>Try It Yourself</h2>
|
||||
<div class="alert important">
|
||||
<p>
|
||||
The sample code is designed to teach you how to use the Dinkey Pro/FD API in Java programs.
|
||||
Do not copy the examples verbatim into your own code. Experiment with the sample code to understand how the API works,
|
||||
and read the chapter <span class="manual">Increasing Your Protection</span> in the user manual for many suggestions on how to
|
||||
make the best use of the API features.
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
<span class="filepath">DPSample.java</span> gives simple examples of performing a protection check,
|
||||
as well as using various other features of Dinkey Pro/FD.
|
||||
To run the DPSample program you will first need to use DinkeyAdd to produce a locked copy of the native library for your platform,
|
||||
and program a dongle (if you are using Plus or Net dongles).
|
||||
Place the locked library in one of the paths specified by your Java environment's <code>java.library.path</code> system property.
|
||||
Browse the examples in <span class="filepath">DPSample.java</span> to see how different features can be used.
|
||||
All the examples follow the same basic pattern:
|
||||
</p>
|
||||
<ol>
|
||||
<li>Create a DinkeyPro instance and set up its internal DRIS with the relevant information.</li>
|
||||
<li>Call the API.</li>
|
||||
<li>Use the information returned in the internal DRIS.</li>
|
||||
</ol>
|
||||
<p>
|
||||
Uncomment the calls at the top of the <code>main()</code> method in <span class="filepath">DPSample.java</span>
|
||||
to enable the examples of different features, then recompile and run DPSample to run the examples.
|
||||
</p>
|
||||
<p>
|
||||
Parts of the sample code marked with <code>!!!!</code> must be customised with your own functions or values
|
||||
for some features to work correctly. Not all features are supported by all dongle models.
|
||||
See the user manual for more information.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user