cbcEncrypt method
Encrypts with CBC and no padding; data must be block-aligned.
Used by Algorithm 2.B and by test fixtures (with PKCS#7 applied by
the caller).
Implementation
Uint8List cbcEncrypt(List<int> iv, Uint8List data) {
assert(data.length % 16 == 0);
final out = Uint8List(data.length);
var prev = Uint8List.fromList(iv);
final block = Uint8List(16);
for (var offset = 0; offset < data.length; offset += 16) {
for (var i = 0; i < 16; i++) {
block[i] = data[offset + i] ^ prev[i];
}
_encryptBlock(block);
out.setRange(offset, offset + 16, block);
prev = Uint8List.sublistView(out, offset, offset + 16);
}
return out;
}