init method

  1. @override
void init(
  1. bool forEncryption,
  2. covariant CipherParameters params
)

Init the cipher with its initialization params. The type of CipherParameters depends on the algorithm being used (see the documentation of each implementation to find out more).

Use the argument forEncryption to tell the cipher if you want to encrypt or decrypt data.

Implementation

@override
void init(bool forEncryption, covariant CipherParameters params) {
  _forEncryption = forEncryption;
  KeyParameter key;

  if (params is AEADParameters) {
    nonce = params.nonce;
    aad = params.associatedData;
    macSize = _getMacSize(forEncryption, params.macSize);
    key = params.parameters as KeyParameter;
  } else if (params is ParametersWithIV<KeyParameter>) {
    nonce = params.iv;
    aad = null;
    macSize = _getMacSize(forEncryption, 64);
    key = params.parameters!;
  } else {
    throw ArgumentError('Invalid parameter class');
  }

  if (nonce.length < 7 || nonce.length > 13) {
    throw ArgumentError('nonce must have length from 7 to 13 octets');
  }

  _keyParam = key;

  reset();
}