dartrosa_encryption library

Encrypted ODK submissions for DartRosa.

A port of ODK Collect's EncryptionUtils: when a form's <submission> has a base64RsaPublicKey, the submission XML and its attachments are encrypted with a random AES key (itself RSA-encrypted with the form's key) and replaced by a plaintext manifest, decryptable by ODK Central and ODK Briefcase.

final encrypted = encryptSubmission(xmlBytes, {'photo.jpg': photo}, form);
if (encrypted != null) {
  upload(encrypted.manifestBytes, encrypted.encryptedFiles);
}

Classes

EncryptedFormInformation
The per-submission encryption state: the random AES key, its RSA encryption, the IV sequence and the element signature being built.
EncryptedSubmission
An encrypted submission: the plaintext manifest to submit as xml_submission_file and the encrypted files to attach.
RsaPublicKey
An RSA public key, as read from a form's <submission base64RsaPublicKey="...">.

Constants

base64RsaPublicKeyAttribute → const String
The <submission> attribute holding the form's public key.
encryptedFileSuffix → const String
The suffix of encrypted files.
encryptedSubmissionNamespace → const String
The namespace of the submission manifest.
openRosaNamespace → const String
The OpenRosa namespace (of orx:meta).
submissionXmlFileName → const String
The name Collect gives the submission file.

Functions

encryptSubmission(Uint8List submissionXml, Map<String, Uint8List> attachments, FormDef form, {String? instanceId, Random? random}) → EncryptedSubmission?
Encrypts a submission of form if the form asks for encryption: its submissionXml and attachments (name → content).
generateEncryptedSubmission(EncryptedFormInformation formInfo, {required Uint8List submissionXml, Map<String, Uint8List> mediaFiles = const {}, String submissionXmlName = submissionXmlFileName}) → EncryptedSubmission
Encrypts submissionXml and mediaFiles (name → content, encrypted in iteration order) with formInfo and builds the submission manifest.
getEncryptedFormInformation(FormDef form, {String? instanceId, Random? random}) → EncryptedFormInformation?
The encryption information for submitting form's current primary instance, or null if the form isn't encrypted (its <submission> has no base64RsaPublicKey).

Exceptions / Errors

EncryptionException
Thrown when a form asks for encryption but the submission can't be encrypted (no instance ID, invalid public key, ...).