Class RsaKeyGenSpec

java.lang.Object
zeroecho.core.alg.rsa.RsaKeyGenSpec
All Implemented Interfaces:
Describable, AlgorithmKeySpec

public final class RsaKeyGenSpec extends Object implements AlgorithmKeySpec, Describable
Key generation specification for RSA key pairs.

This spec defines the modulus length and public exponent used when generating an RSA key pair. It is passed to the algorithm’s key builder (see RsaAlgorithm) to produce a KeyPair.

Parameters

  • keySize: the RSA modulus size in bits. Must be at least 1024; typical secure values are 2048 or 3072, with 4096 used for high-security applications.
  • publicExponent: the RSA public exponent. The common and recommended value is 65537 (F4), balancing security and performance.

Usage example

// Create a spec for a 2048-bit key with exponent 65537
RsaKeyGenSpec spec = RsaKeyGenSpec.rsa2048();

// Generate the key pair
KeyPair kp = rsaAlgorithm.asymmetricKeyPairGenerator(RsaKeyGenSpec.class)
                         .generateKeyPair(spec);
Since:
1.0
  • Constructor Details

    • RsaKeyGenSpec

      public RsaKeyGenSpec(int keySize, int publicExponent)
      Constructs an RSA key generation spec with the given parameters.
      Parameters:
      keySize - modulus size in bits; must be at least 1024
      publicExponent - RSA public exponent, usually 65537
      Throws:
      IllegalArgumentException - if keySize is smaller than 1024 or the exponent is not odd and at least 3
  • Method Details

    • keySize

      public int keySize()
      Returns the modulus length in bits.
      Returns:
      RSA modulus size
    • publicExponent

      public int publicExponent()
      Returns the public exponent.
      Returns:
      RSA public exponent (typically 65537)
    • rsa2048

      public static RsaKeyGenSpec rsa2048()
      Convenience factory for a 2048-bit RSA spec with exponent 65537.
      Returns:
      new RsaKeyGenSpec instance for 2048/65537
    • rsa3072

      public static RsaKeyGenSpec rsa3072()
      Convenience factory for a 3072-bit RSA spec with exponent 65537.
      Returns:
      new RsaKeyGenSpec instance for 3072/65537
    • rsa4096

      public static RsaKeyGenSpec rsa4096()
      Convenience factory for a 4096-bit RSA spec with exponent 65537.
      Returns:
      new RsaKeyGenSpec instance for 4096/65537
    • description

      public String description()
      Returns a short description string.

      Format is "<keySize>:<publicExponent>", for example "2048:65537".

      Specified by:
      description in interface Describable
      Returns:
      human-readable description of this spec