init method

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

Init the signer 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 forSigning to tell the signer if you want to generate or verify signatures.

Implementation

@override
void init(bool forSigning, CipherParameters params) {
  _forSigning = forSigning;

  AsymmetricKeyParameter akparams;
  if (params is ParametersWithSaltConfiguration) {
    akparams = params.parameters as AsymmetricKeyParameter<AsymmetricKey>;
    _random = params.random;
    _sSet = false;
    _sLen = params.saltLength;
    _salt = Uint8List(_sLen);
  } else if (params is ParametersWithSalt) {
    akparams = params.parameters as AsymmetricKeyParameter<AsymmetricKey>;
    _sSet = true;
    _salt = params.salt;
    _sLen = _salt.length;
  } else {
    throw ArgumentError(
        'Unsupported parameters type ${params.runtimeType}: should be ParametersWithSaltConfiguration or ParametersWithSalt');
  }

  var k = akparams.key as RSAAsymmetricKey;

  if (forSigning && (k is! RSAPrivateKey)) {
    throw ArgumentError('Signing requires private key');
  }

  if (!forSigning && (k is! RSAPublicKey)) {
    throw ArgumentError('Verification requires public key');
  }

  _emBits = k.modulus!.bitLength - 1;

  if (_emBits < (8 * _hLen + 8 * _sLen + 9)) {
    throw ArgumentError('Key too small for specified hash and salt lengths');
  }

  _mDash = Uint8List(8 + _sLen + _contentDigest.digestSize);

  _cipher.init(forSigning, akparams);

  _block = Uint8List((_emBits + 7) ~/ 8);

  reset();
}