Message Digests

1.0 Overview

The Fortanix DSM can calculate standard message digests such as SHA-1 and SHA-256. However, since computing these hashes does not involve any cryptographic secrets, it is generally more convenient and more efficient to calculate non-authenticated message digests on the client. In java, the java.security.MessageDigest class can be used to compute message digests in code. Or programs such as sha1sum or sha256sum can be used to calculate message digests on the command line.

2.0 Prerequisites

Computing message digests requires a Fortanix DSM account, a group, and an application configured in that group. See the Fortanix Data Security Manager Getting Started Guide for more details.

3.0 Authorization and Configuration

You must first authenticate and optionally configure a default API client as described in Configure API Client and Client Authentication. Computing a message digest requires authenticating as an app with an API key or a client certificate. (User accounts cannot compute message digests).

4.0 Create a DigestApi Client Object

Message digests are computed using a DigestApi object.

import com.fortanix.sdkms.v1.api.DigestApi;

DigestApi digestApi = new DigestApi();

5.0 Create a DigestRequest

The DigestRequest object contains the requested message digest algorithm and the data to be hashed. The data should be binary data passed as an array of bytes.

import com.fortanix.sdkms.v1.model.DigestAlgorithm;
import com.fortanix.sdkms.v1.model.DigestRequest;

DigestRequest digestRequest = new DigestRequest().alg(DigestAlgorithm.<Algorithm name>).data(<input data as bytes[]>);

6.0 Make the Digest Call

The digest is computed by calling the computeDigest() method of a DigestApi() object with the DigestRequest. This method will return a DigestResponse containing the message digest. The message digest is returned in binary as an array of bytes. Note that command line tools typically return message digests as strings of hexidecimal digits. You will need to convert the output to this format if you want hexadecimal.

import com.fortanix.sdkms.v1.model.DigestResponse;

DigestResponse digestResponse = digestApi.computeDigest(digestRequest);
byte[] digest = digestResponse.getDigest();