# 5.5 XAdES Signature API
# Use cases
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.
# Tools
# Dart
- Plugin http
- Plugin http_parser
# Kotlin
- Library OkHttp
# Background
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.
# Step by step sequence
- Get the certificate;
- Get the document;
- Build the request;
- 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('/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();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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.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
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34