decryptBatch static method
List<ScanResult> ?
decryptBatch(
- EncryptedScanData encrypted, {
- required String password,
- bool ignoreExpiry = false,
Decrypts a batch-encrypted bundle back to a list of ScanResult.
Implementation
static List<ScanResult>? decryptBatch(
EncryptedScanData encrypted, {
required String password,
bool ignoreExpiry = false,
}) {
if (!ignoreExpiry && encrypted.isExpired) return null;
final key = _deriveKey(password, encrypted.salt, keyLength: 32);
final decryptedBytes =
_xorDecrypt(encrypted.ciphertext, key, encrypted.iv);
try {
final jsonStr = utf8.decode(decryptedBytes);
final jsonMap = jsonDecode(jsonStr) as Map<String, dynamic>;
final batch = jsonMap['batch'] as List<dynamic>;
return batch
.map((item) =>
_scanResultFromJson(item as Map<String, dynamic>))
.toList();
} catch (_) {
throw EncryptionException(
'Batch decryption failed — incorrect password or corrupted data');
}
}