Class RsaSigSpec

java.lang.Object
zeroecho.core.alg.rsa.RsaSigSpec
All Implemented Interfaces:
Describable, ContextSpec

public final class RsaSigSpec extends Object implements ContextSpec, Describable
Specification of RSA signature parameters including padding mode, hash function, and (for PSS) salt length.

This spec is used with RsaSignatureContext to configure how RSA signatures are created and verified. It supports two modes:

Construction

Use the static factories to create a spec:
// PKCS#1 v1.5 with SHA-256
RsaSigSpec pkcs1 = RsaSigSpec.pkcs1v15(RsaSigSpec.Hash.SHA256);

// PSS with SHA-384 and salt length equal to digest length
RsaSigSpec pss = RsaSigSpec.pss(RsaSigSpec.Hash.SHA384, -1);

// PSS with SHA-512 and explicit 32-byte salt
RsaSigSpec pss32 = RsaSigSpec.pss(RsaSigSpec.Hash.SHA512, 32);

Security notes

  • PSS is recommended over PKCS#1 v1.5 for new applications, as it provides stronger provable security.
  • The default salt length of -1 means “use the digest length”, as recommended by PKCS#1.
  • PKCS#1 v1.5 signatures remain widely used for compatibility but are less robust against certain attack classes.
Since:
1.0
  • Method Details

    • pkcs1v15

      public static RsaSigSpec pkcs1v15(RsaSigSpec.Hash h)
      Creates a PKCS#1 v1.5 spec with the given hash.
      Parameters:
      h - hash algorithm
      Returns:
      new RsaSigSpec instance for PKCS#1 v1.5
    • pss

      public static RsaSigSpec pss(RsaSigSpec.Hash h, int saltLen)
      Creates a PSS spec with the given hash and salt length.

      A salt length of -1 means “use digest length”, as recommended by PKCS#1.

      Parameters:
      h - hash algorithm
      saltLen - PSS salt length, or -1 for digest length
      Returns:
      new RsaSigSpec instance for PSS
    • fromSignatureAlgorithmId

      public static Optional<RsaSigSpec> fromSignatureAlgorithmId(String algorithmId)
      Resolves a standard external signature algorithm identifier to an explicit RSA signature specification.

      This helper is intended for interoperability with ecosystems that express RSA signature semantics through integrated names such as SHA256withRSA. The returned spec always preserves the caller-visible semantics instead of relying on algorithm defaults.

      Parameters:
      algorithmId - canonical external signature algorithm identifier
      Returns:
      matching RSA signature spec, or Optional.empty() when the identifier is not a supported RSA interop name
    • mode

      public RsaSigSpec.Mode mode()
      Returns the signature mode.
      Returns:
      mode (PKCS#1 v1.5 or PSS)
    • hash

      public RsaSigSpec.Hash hash()
      Returns the hash algorithm.
      Returns:
      hash algorithm used for signing/verification
    • pssSaltLen

      public int pssSaltLen()
      Returns the salt length for PSS.
      Returns:
      salt length in bytes, or -1 to indicate digest length
    • description

      public String description()
      Returns a short human-readable description of this spec.

      Examples:

      • "PKCS1v1.5(SHA256)"
      • "PSS(SHA512,salt=32)"
      • "PSS(SHA384,salt=digestLen)"
      Specified by:
      description in interface Describable
      Returns:
      description string