decryptData method
Decrypt data after reading.
Expects base64-encoded encrypted data with IV/nonce prepended.
Implementation
String decryptData(String ciphertext) {
if (!config.enabled) return ciphertext;
try {
String decrypted;
switch (config.algorithm) {
case EncryptionAlgorithm.aes256GCM:
decrypted = _decryptAesGcm(ciphertext);
break;
case EncryptionAlgorithm.aes256CBC:
decrypted = _decryptAesCbc(ciphertext);
break;
case EncryptionAlgorithm.chacha20Poly1305:
decrypted = _decryptChaCha20(ciphertext);
break;
}
// Decompress if enabled
if (config.compressBeforeEncryption) {
final compressed = base64.decode(decrypted);
final decompressed = gzip.decode(compressed);
return utf8.decode(decompressed);
}
return decrypted;
} catch (e) {
throw EncryptionException('Decryption failed: $e');
}
}