# 5.2 Simple Electronic Signature with a Self Signed Certificate in your DDO
# Use cases
Takes the given data, converts it to an alphabetically sorted JSON object and signs its content using the given wallet.
# Tools
The Commercio SDK, our own open source tool to format transactions to Commercio.network
# Functions and APIs
- SignHelper signSorted.
- CertificateHelper getPem (only for Kotlin).
# Background
From Wikipedia:
In cryptography and computer security, a self-signed certificate is a certificate that is not signed by a certificate authority (CA). Privacy-Enhanced Mail (PEM) is a de facto file format for storing and sending cryptographic keys, certificates, and other data, based on a set of 1993 IETF standards defining "privacy-enhanced mail.
# Step by step sequence
# Dart
- Execute the SignHelper signSorted to sign your data.
# Kotlin
# signSorted
- Generate the wallet;
- Execute the SignHelper signSorted to sign your data. The resulting byte array represents the signature in ASN.1 DER format.
# getPEM
- Generate the wallet;
- Generate rsaKeyPair using KeysHelper generateRsaKeyPair;
- Create an X509 certificate using the given keyPair and walletAddress;
- Execute CertificateHelper getPem to get PEM representation of the given certificate.
# Code Examples
Here's an example of the implemetation in all the available languages.
# Dart
final data = {
"name": "John",
"surname": "Smith",
"email": "jsmith@test.com"
};
await SignHelper.signSorted(data, wallet);
1
2
3
4
5
6
7
2
3
4
5
6
7
# Kotlin
# signSorted
val data ="\"name\": \"John\", \"surname\": \"Smith\",\"email\": \"jsmith@test.com\""
val wallet = Wallet.derive(mnemonic, networkInfo)
val signedData = SignHelper.signSorted(data, wallet)
1
2
3
4
5
2
3
4
5
# getPEM
val wallet = Wallet.derive(mnemonic, networkInfo)
val rsaKeyPair = KeysHelper.generateRsaKeyPair()
val certificate = CertificateHelper.x509certificateFromWallet(wallet.bech32Address, rsaKeyPair)
val pemCertificate = CertificateHelper.getPem(certificate)
1
2
3
4
5
6
7
2
3
4
5
6
7
# C#
var wallet = commercio.sacco.lib.Wallet.derive(mnemonic, networkInfo);
var data = "{'name': 'John', 'surname': 'Smith', 'email': 'jsmith@test.com'}";
var res = commercio.sdk.SignHelper.signSorted(data, wallet);
1
2
3
4
5
2
3
4
5