parsePayload function
Implementation
Map<String, dynamic> parsePayload(String payload) {
if (payload.isEmpty || payload[0] == '#') {
throw Exception('Unknown version');
}
if (payload.length < 132 || payload.length > 87472) {
throw Exception('Invalid payload size');
}
Uint8List data = base64.decode(payload);
if (data[0] != 0x02) {
throw Exception('Unsupported version');
}
Uint8List nonce = data.sublist(1, 33);
Uint8List mac = data.sublist(data.length - 32);
Uint8List ciphertext = data.sublist(33, data.length - 32);
return {
'nonce': nonce,
'ciphertext': ciphertext,
'mac': mac,
};
}