init method

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

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, CipherParameters params) {
  AsymmetricKeyParameter akparams;
  mgf1Hash = hash;
  if (params is ParametersWithRandom) {
    var paramswr = params;
    _random = paramswr.random;
    akparams = paramswr.parameters as AsymmetricKeyParameter<AsymmetricKey>;
  } else {
    _random = FortunaRandom();
    _random.seed(KeyParameter(_seed()));
    akparams = params as AsymmetricKeyParameter<AsymmetricKey>;
  }
  _engine.init(forEncryption, akparams);
  _forEncryption = forEncryption;

  // Check type of key provided is suitable
  // Note: the _engine can't do this check, because the engine could be used
  // for both encryption/decryption and signature/verification (which reverses
  // the keys), so its `init` method accepts both types of keys. For example,
  // [RSAEngine.init].

  if (forEncryption) {
    if (akparams.key is! PublicKey) {
      throw ArgumentError.value(
          'OAEP encryption needs PublicKey: not ${akparams.key.runtimeType}');
    }
  } else {
    if (akparams.key is! PrivateKey) {
      throw ArgumentError.value(
          'OAEP decryption needs PrivateKey: not ${akparams.key.runtimeType}');
    }
  }
}