Prepares the XML document in order to be signed from user with his private signing key linked to the public one inside the certificate; applies XAdES signature.
- Plugin http
- Plugin http_parser
- Library OkHttp
From Wikipedia:
XAdES (short for "XML Advanced Electronic Signatures") is a set of extensions to XML-DSig recommendation making it suitable for advanced electronic signatures.
- Get the certificate;
- Get the document;
- Build the request;
- Finally, send the request.
Here's an example of the implemetation in all the available languages.
var certificate = File('/pems/certificate.pem');
var document = File('/xmls/document.xml');
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();
val requestBody: RequestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart(
"certificate", "certificate.pem",
File("/pems/certificate.pem")
.asRequestBody("application/octet-stream".toMediaTypeOrNull())
)
.addFormDataPart(
"document", "document.xml",
File("/xmls/document.xml")
.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
}
})