Skip to content

Latest commit

 

History

History
96 lines (77 loc) · 2.4 KB

File metadata and controls

96 lines (77 loc) · 2.4 KB

5.4 PAdES Signature API

Use cases

Prepares the PDF document in order to be signed from user with his private signing key linked to the public one inside the certificate; applies PAdES signature.

Tools

Dart

  • Plugin http
  • Plugin http_parser

Kotlin

  • Library OkHttp

Background

From Wikipedia:

PAdES (PDF Advanced Electronic Signatures) is a set of restrictions and extensions to PDF and ISO 32000-1[1] making it suitable for Advanced Electronic Signature.

Step by step sequence

  1. Get the certificate;
  2. Get the document;
  3. Build the request;
  4. Finally, send the request.

Code Examples

Here's an example of the implemetation in all the available languages.

Dart

var certificate = File('/pems/certificate.pem');
var document = File('/pdfs/document.pdf');
var uri = Uri.parse(
    'https://api.commercio.network/sign/signature');
var request = new http.MultipartRequest('POST', uri);
request.files.add(
  await http.MultipartFile.fromPath(
    'certificate',
    certificate.path,
    contentType: new MediaType('application', 'x-tar'),
  ),
);
request.files.add(
  await http.MultipartFile.fromPath(
    'document',
    document.path,
    contentType: new MediaType('application', 'x-tar'),
  ),
);
http.StreamedResponse response = await request.send();

Kotlin

val requestBody: RequestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
    .addFormDataPart(
        "certificate", "certificate.pem",
        File("/pems/certificate.pem")
            .asRequestBody("application/octet-stream".toMediaTypeOrNull())
    )
    .addFormDataPart(
        "document", "document.pdf",
        File("/pdfs/document.pdf")
            .asRequestBody("application/octet-stream".toMediaTypeOrNull())
    )
    .addFormDataPart("type", "")
    .addFormDataPart("message", "")
    .addFormDataPart("signedMessage", "")
    .addFormDataPart("signedDecodingType", "")
    .build()

val okHttpClient = OkHttpClient()
val request = Request.Builder()
    .method("POST", requestBody)
    .url("https://api.commercio.network/sign/signature")
    .build()
okHttpClient.newCall(request).enqueue(object : Callback {
    override fun onFailure(call: Call, e: IOException) {
        // Handle this
    }

    override fun onResponse(call: Call, response: Response) {
        if (!response.isSuccessful) {
            // Handle the error
        }
        // Upload successful
    }
})