Inadequate encryption strength due to insufficient key size

ID

dart.cryptography.insufficient_key_size

Severity

high

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Cryptography

Language

Dart

Description

A cryptographic key is generated below modern minimum sizes (RSA / DH < 2048 bits, AES < 128 bits, EC curves with order < 256 bits). Smaller keys are factorable or brute-forceable with present-day compute.

Rationale

Recommended minimums (NIST SP 800-57, OWASP, ENISA, BSI all agree):

  • RSA and Diffie-Hellman: 2048 bits minimum, 3072+ for long-lived secrets. 1024-bit factoring is feasible on academic clusters; 768-bit has been done publicly (TWIRL / Logjam) and dropped to a few months on nation-state hardware.

  • Symmetric (AES, ChaCha20): 128 bits minimum, 256 bits recommended for forward-secret-required contexts.

  • Elliptic curves: order >= 256 bits — P-256, Curve25519, secp256k1, secp384r1. P-192 and lower are out.

Static analysis catches the literal-integer form most often. Dynamic attacker scenarios for an undersized key range from passive plaintext recovery (offline factoring of a stored ciphertext / signature) to outright forgery of authentication tokens.

The following code illustrates a vulnerable pattern detected by this rule:

class SmallKeys {
  void pcRsaWeak() {
    // VULNERABLE: Inadequate encryption strength due to insufficient key size
    final p1 = RSAKeyGeneratorParameters(BigInt.from(65537), 1024, 64);
    // VULNERABLE: Inadequate encryption strength due to insufficient key size
    final p2 = RSAKeyGeneratorParameters(BigInt.from(65537), 512, 64);
    // VULNERABLE: Inadequate encryption strength due to insufficient key size
    final p3 = RSAKeyGeneratorParameters(BigInt.from(65537), 1536, 64);
    print('$p1 $p2 $p3');
  }
}

Remediation

Use the recommended minimums above. Both package:pointycastle and package:cryptography accept these sizes via named-argument or factory constructors.

// Vulnerable
RSAKeyGeneratorParameters(BigInt.from(65537), 1024, 64);
Encrypter(RSA(... encoding: RSAEncoding.PKCS1));
Key.fromLength(8);   // 64-bit AES key

// Fixed
RSAKeyGeneratorParameters(BigInt.from(65537), 3072, 64);
// Or the modern AEAD alternative:
final aead = AesGcm.with256bits();

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved