public static void checkKeyLengths(int modulusLen,BigInteger exponent,int minModulusLen,int maxModulusLen) throws InvalidKeyException {
  if ((minModulusLen > 0) && (modulusLen < (minModulusLen))) {
    throw new InvalidKeyException("RSA keys must be at least " + minModulusLen + " bits long");
  }
  int maxLen=Math.min(maxModulusLen,MAX_MODLEN);
  if (modulusLen > maxLen) {
    throw new InvalidKeyException("RSA keys must be no longer than " + maxLen + " bits");
  }
  if (restrictExpLen && (exponent != null) && (modulusLen > MAX_MODLEN_RESTRICT_EXP)&& (exponent.bitLength() > MAX_RESTRICTED_EXPLEN)) {
    throw new InvalidKeyException("RSA exponents can be no longer than " + MAX_RESTRICTED_EXPLEN + " bits "+ " if modulus is greater than "+ MAX_MODLEN_RESTRICT_EXP+ " bits");
  }
}

public static void checkKeyLengths ( int modulusLen , BigInteger exponent , int minModulusLen , int maxModulusLen ) throws InvalidKeyException { if ( ( minModulusLen > 0 ) && ( modulusLen < ( minModulusLen ) ) ) { throw new InvalidKeyException ( "RSA keys must be at least " + minModulusLen + " bits long" ) ; } int maxLen = Math . min ( maxModulusLen , MAX_MODLEN ) ; if ( modulusLen > maxLen ) { throw new InvalidKeyException ( "RSA keys must be no longer than " + maxLen + " bits" ) ; } if ( restrictExpLen && ( exponent != null ) && ( modulusLen > MAX_MODLEN_RESTRICT_EXP ) && ( exponent . bitLength ( ) > MAX_RESTRICTED_EXPLEN ) ) { throw new InvalidKeyException ( "RSA exponents can be no longer than " + MAX_RESTRICTED_EXPLEN + " bits " + " if modulus is greater than " + MAX_MODLEN_RESTRICT_EXP + " bits" ) ; } }
check the length of an rsa key modulus / exponent to make sure it is not too short or long . some impls have their own min and max key sizes that may or may not match with a system defined value .
