sandeep singh
sandeep singh

Reputation: 19

Need help for integrating our custom application with CoSign Signature(JSON)

We are working on a CoSign Signature API app. We are using the 7.1 documentation.

As mentioned in the documentation, to work on “CoSign Signature," we need to have the ARX ROOT certificate to establish the SSL session with the CoSign Appliance.

Please help us to get this certificate.

Also please provide us the testing url’s for the same. It will be great if you can provide us some examples for using this API with java

Upvotes: 0

Views: 151

Answers (1)

Almog G.
Almog G.

Reputation: 817

First note that a newer version of the documentation is available - CoSign Signature API v7.2.

Here you can find an explanation on how to download the root CA certificate.

Our DevPortal will soon be updated with more code samples. Meanwhile, here is a basic sample code in Java that demonstrates how to sign a PDF using the CoSign Signature API:

public static byte[] SignPDF(byte[] fileBuffer) throws Exception {

    byte[] signedFileBuffer = null;
    String baseUrl = "https://prime.cosigntrial.com:8081/sapiws";

    CloseableHttpClient httpclient = HttpClients.createDefault();

    try {

        String base64Data = new String(Base64.encodeBase64(fileBuffer));

        // Build request body (JSON formatted)
        JSONObject json = new JSONObject();
        json.put("Username", "{username}");
        json.put("password", "{password}");
        json.put("FileData", base64Data);
        json.put("FileType", "pdf");
        json.put("Page", -1);
        json.put("X", 145);
        json.put("Y", 125);
        json.put("Width", 160);
        json.put("Height", 45);

        StringEntity stringEntity = new StringEntity(json.toString());

        HttpPost httpPost = new HttpPost(baseUrl + "/CreateSign" );
        // Set Content-Type request header
        httpPost.addHeader("content-type", "application/json");
        // Add request body
        httpPost.setEntity(stringEntity);
        // Send the request
        CloseableHttpResponse httpResponse = httpclient.execute(httpPost);

        HttpEntity httpEntity = httpResponse.getEntity();
        InputStream inputStream = httpEntity.getContent();
        String response = IOUtils.toString(inputStream, "UTF-8");

        // Parse JSON formatted response and fetch signed content on success
        JSONObject responseJson = new JSONObject(response);
        if (responseJson.getBoolean("Success")) {
            String signedFileBase64 = responseJson.getJSONObject("Data").getString("SignedFileData");
            signedFileBuffer = Base64.decodeBase64(signedFileBase64);
        }
    } finally {
        if(httpclient != null)
            httpclient.close();
    }

    return signedFileBuffer;
}

Upvotes: 1

Related Questions