0

我们正在开发 CoSign 签名 API 应用程序。我们正在使用7.1 文档。

如文档中所述,要使用“CoSign 签名”,我们需要拥有 ARX ROOT 证书才能与 CoSign 设备建立 SSL 会话。

请帮助我们获得此证书。

也请向我们提供相同的测试网址。如果您能给我们提供一些在java中使用此 API 的示例,那就太好了

4

1 回答 1

1

首先请注意,可以使用更新版本的文档 - CoSign Signature API v7.2

在这里您可以找到有关如何下载根 CA 证书的说明。

我们的 DevPortal 将很快更新更多代码示例。同时,这里是一个基本的 Java 示例代码,演示了如何使用 CoSign Signature API 对 PDF 进行签名:

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;
}
于 2015-03-02T17:31:29.610 回答