Decryptx Java SDK

How to download and install the Decryptx Java software development kit (SDK) and use it with Maven.

To use the Decryptx Java libraries provided, you have to set them up in your project. Our example uses a build automation software called Maven because it's a popular choice for Java projects. You may use whatever build automation software you prefer, however the steps may not be exactly the same.

To access the complete Decryptx Java Docs, click here.

Download the Code

Download the source code for Decryptx Client 1.0.0 & Decryptx Parser 1.3.0.

Maven Setup

In order to use the SDK, you will need to install several dependencies. The best way to do that is to include them in your Maven pom.xml:

First, install the Decryptx jar into your local Maven repository.

mvn install:install-file
    	-Dfile=path/to/jar/decryptx-client-1.0.0.jar
      -DgroupId=com.bluefin.decryptx
      -DartifactId=decryptx-client
      -Dversion=1.0.0
      -Dpackaging=jar

To add the Decryptx Parser to your local Maven repository.

mvn install:install-file -Dfile=path/to/jar/decryptx-parser-1.3.0.jar -DgroupId=com.bluefin.decryptx -DartifactId=decryptx-parser -Dversion=1.3.0 -Dpackaging=jar

Add the required dependencies to your pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  

 <!-- More configuration options here-->
      
  <dependencies>

    <!-- HTTP client: jersey-client -->
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <version>${jersey-version}</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey.contribs</groupId>
      <artifactId>jersey-multipart</artifactId>
      <version>${jersey-version}</version>
    </dependency>

    <!-- JSON processing: jackson -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>${jackson-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
      <version>${jackson-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-joda</artifactId>
      <version>2.1.5</version>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>${jodatime-version}</version>
    </dependency>
    <dependency>
        <groupId>com.bluefin.decryptx</groupId>
        <artifactId>decryptx-client</artifactId>
        <version>${decryptx-client-version}</version>
    </dependency>
    <!-- uncomment to add Parser client
    <dependency>
        <groupId>com.bluefin.decryptx</groupId>
        <artifactId>decryptx-parser</artifactId>
        <version>${decryptx-parser-version}</version>
    </dependency>
    -->
  </dependencies>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jersey-version>1.18</jersey-version>
    <jackson-version>2.4.2</jackson-version>
    <jodatime-version>2.3</jodatime-version>
    <decryptx-client-version>1.3.0</decryptx-client-version>
    <decryptx-parser-version>1.0.0</decryptx-parser-version>
    <maven-plugin-version>1.0.0</maven-plugin-version>
  </properties>
</project>

Initialise the SDK

To use the Java SDK, first initialise the DecryptxApi object:

import com.bluefin.decryptx.apis.DecryptxApi;

final DecryptxApi decryptxApi = new DecryptxApi();

Development vs. Production

All these examples use the Decryptx production environment. To evaluate your requests against the certification environment, update the base path of the DecryptxApi REST Client.

At Bluefin, we protect our REST endpoints with a IP address whitelist. If you would like to try the examples below, please contact us to request access.

//point the DecryptxApi Client to certification environment.

decryptxApi.getApiClient().setBasePath("https://secure-cert.decryptx.com/api");

Authentication Headers

As of version 1.1.0, we have updated our Java SDK to support the Basic, Digest, HMAC, and RSA authentication methods. For more details on these new methods see our Authentication (HMAC/RSA Guide. If you specify your desired authentication method and credentials when instantiating the DecryptxApi object, the SDK will automatically generate the authentication headers needed.

final DecryptxApi decryptxApi = new DecryptxApi( 
  AuthenticationMethod.HMAC,
  "?????????",
  "ef1ad938150fb15a1384b883a104ce70" );

If the DecryptxApi object is instantiated without specifying an authentication method, then the credentials must be sent in the body of the API request.

Validate Account

To test your Bluefin credentials against our /api/partner/validate endpoint use the validatePartner method.

final PartnerParam partnerParam = new PartnerParam()
        .partnerId("?????????")
        .partnerKey("ef1ad938150fb15a1384b883a104ce70")
        .reference("723f57e1-e9c8-48cb-81d9-547ad2b76435");

final ValidationResponse resp = decryptxApi.validatePartner(partnerParam);

if (resp.isSuccess()){
    System.out.println("success    :" + resp.isSuccess());
    System.out.println("message id :" + resp.getMessageId());
    System.out.println("reference  :" + resp.getReference());
}
else{
    System.out.println("failed :(");
}
success    :true
message id :1201607010831171011230067
reference  :723f57e1-e9c8-48cb-81d9-547ad2b76435

Validate Device

Next, check that your device is correctly registered against your account by using the validateDevice method of the DecryptxApi object.

final DeviceParam deviceParam = new DeviceParam()
        .partnerId("?????????")
        .partnerKey("ef1ad938150fb15a1384b883a104ce70")
        .reference("723f57e1-e9c8-48cb-81d9-547ad2b76435")
        .serial("541T112708")
        .clientId("bobs_burgers");

final ValidationResponse resp = decryptxApi.validateDevice(deviceParam);

if (resp.isSuccess()){
    System.out.println("success    :" + resp.isSuccess());
    System.out.println("message id :" + resp.getMessageId());
    System.out.println("reference  :" + resp.getReference());
}
else{
    System.out.println("failed :(");
}
success    :true
message id :1201607010831171011230067
reference  :723f57e1-e9c8-48cb-81d9-547ad2b76435

Decrypt

final DecryptxApi decryptxApi = new DecryptxApi();

decryptxApi.getApiClient().setBasePath("https://secure-cert.decryptx.com/api");

//build up parameter object
final DecryptParam params = new DecryptParam()
     .partnerId("?????????")
     .partnerKey("ef1ad938150fb15a1384b883a104ce70")
     .reference("723f57e1-e9c8-48cb-81d9-547ad2b76435")
     .clientId("my_client")
     .hasCcData(DecryptParam.HasCcDataEnum._1)
     .serial("541T112708")
     .decryptionParameters(new DecryptionParameters()
             .sequenceNumber("629949960E001D200037")
             .encoding(DecryptionParameters.EncodingEnum.HEX));

//Add track data to decrypt.
final List<Encrypted> encryptedList = new ArrayList<Encrypted>();

encryptedList.add(new Encrypted()
                 .name("track1")
                 .value("EF77ABC20DE782C48A88FBF25C59A6C7E21FD7E42D9A1C091F5FC8BBC1BF7DA89E2D8DB1AEB58A7318A79DDE4E59A5E7BD682FCAE9F6BBFD"));

encryptedList.add(new Encrypted()
                 .name("track2")
                 .value("7EF02FC12FD9864672B4DDAE562F4D6EDAB53D91A85A83964A3E4EA545AD7D6CAFBB9D6BB51016E4"));

params.setEncrypted(encryptedList);

final DecryptResponse resp = decryptxApi.decrypt(params);

//process result.
if (resp.isSuccess()){
    System.out.println("success    :" + resp.isSuccess());
    System.out.println("message id : " + resp.getMessageId());
    System.out.println("reference  :" + resp.getReference());
    
    for (final Decrypted decrypted : resp.getDecrypted()){
        //name is always returned
        System.out.println("name  :" + decrypted.getName());
            
        if (null != decrypted.isFailed() && decrypted.isFailed()){
            System.out.println("error code   :" + decrypted.getCode());
            System.out.println("error message: " + decrypted.getMessage());
        }
        else{
            System.out.println("value :" + decrypted.getValue());
        }
    } 
}
success    :true
message id :1201607010825191011016636
reference  :723f57e1-e9c8-48cb-81d9-547ad2b76435
name       :track1
value      :25423337303030303939393939393939305e544553542f424c554546494e5e323231323130313132333435363738393f2800000000000000
name       :track2
value      :3b3337303030303939393939393939303d323231323130313132333435363738393f3f0000000000

Error Handling

If the API call is not successful, errors can be handled by using the try/catch construct with our ApiExceptionUtils class like this:

import com.bluefin.decryptx.ApiException;
import com.bluefin.decryptx.ApiExceptionUtils
import com.bluefin.decryptx.model.DecryptxError;

//more code here

try{
    final ParserParam param = new ParserParam()
                                .reference("723f57e1-e9c8-48cb-81d9-547ad2b76435")
                                .partnerId("not_a_real_key");

    final PayloadDecrypted  decrypted = decryptxApi.processPayload(param);

    // if successful, do something here
}  catch(ApiException e) {

    if ( ApiExceptionUtils.isDecryptxError(e) ){

        //convert the APIException object to a DecryptxError object.
        final DecryptxError err = ApiExceptionUtils.getDecryptxError(e);

        System.err.println("success   : " + err.isSuccess());
        System.err.println("messageId : " + err.getMessageId());
        System.err.println("code      : " + err.getErrCode());
        System.err.println("message   : " + err.getErrMessage());
        System.err.println("reference : " + err.getReference());
    }
    else{
        //a non Decryptx api related error (network issues, etc).
        System.err.println("e: " + e.getMessage());
        System.err.println("code: " + e.getCode());
        System.err.println("body: " + e.getResponseBody());
    }

}
success   : false
messageId : 1201607010822361022502672
code      : 3000
message   : Authentication required.
reference : 723f57e1-e9c8-48cb-81d9-547ad2b76435

The ApiExceptionUtils is a handy helper that will convert the returned exception into a DecryptxError object. The DecryptxError object will contain useful information about the error.