RSAPrivateKey constructor

  1. BigInt modulus,
  2. BigInt privateExponent,
  3. BigInt? p,
  4. BigInt? q, [
  5. @Deprecated('Public exponent is calculated from the other values') BigInt? publicExponent,

Create an RSA private key for the given parameters.

The optional public exponent parameter has been deprecated. It does not have to be provided, because it can be calculated from the other values. The optional parameter is retained for backward compatibility, but it does not need to be provided.


RSAPrivateKey(BigInt modulus, BigInt privateExponent, this.p, this.q,
    [@Deprecated('Public exponent is calculated from the other values')
    BigInt? publicExponent])
    : super(modulus, privateExponent) {
  // Check RSA relationship between p, q and modulus hold true.

  if (p! * q! != modulus) {
    throw ArgumentError.value('modulus inconsistent with RSA p and q');

  // Calculate the correct RSA public exponent

  _pubExp = privateExponent.modInverse((p! - * (q! -;

  // If explicitly provided, the public exponent value must be correct.
  if (publicExponent != null && publicExponent != _pubExp) {
    throw ArgumentError(
        'public exponent inconsistent with RSA private exponent, p and q');