encodePayload static method
Encodes the payload with a given nonce and key. Compresses the content if a key is present before encryption.
Implementation
static String encodePayload(Map<String, dynamic> data,
{required Nonce nonce, ChaCha20? chaCha20, bool compressed = true}) {
if (chaCha20 == null) compressed = false;
String output = jsonEncode(data);
if (!compressed && chaCha20 == null) return output;
if (compressed) {
ZLibEncoder zlibE = ZLibEncoder(level: 9);
output = base64Encode(
zlibE.convert(utf8.encode(output)),
);
}
if (chaCha20 != null) {
return chaCha20.encrypt(output, nonce);
} else {
return output;
}
}