init method
Initialise the cipher for processing.
Implementation
@override
void init(bool forEncryption, CipherParameters params) {
if (params is! KeyParameter) {
throw ArgumentError('DESede requer KeyParameter.');
}
final key = params.key;
if (key.length != 16 && key.length != 24) {
throw ArgumentError('Chave DESede deve ter 16 ou 24 bytes.');
}
_forEncryption = forEncryption;
final k1 = key.sublist(0, 8);
final k2 = key.sublist(8, 16);
final k3 = key.length == 24 ? key.sublist(16, 24) : k1;
// EDE: the middle stage runs in the opposite direction. The subkeys must
// follow the requested direction, as in Bouncy Castle's DESedeEngine;
// fixing them to (encrypt, decrypt, encrypt) made every decryption wrong.
_k1 = DESEngine.generateWorkingKey(forEncryption, k1);
_k2 = DESEngine.generateWorkingKey(!forEncryption, k2);
_k3 = DESEngine.generateWorkingKey(forEncryption, k3);
}