Class RsaSigSpec
java.lang.Object
zeroecho.core.alg.rsa.RsaSigSpec
- All Implemented Interfaces:
Describable, ContextSpec
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:
RsaSigSpec.Mode.PKCS1V15— legacy PKCS#1 v1.5 signatures using a selected hash.RsaSigSpec.Mode.PSS— probabilistic signatures with PSS padding using a selected hash and configurable salt length.
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
-1means “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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSupported hash algorithms for RSA signatures.static enumSignature padding modes supported by RSA. -
Method Summary
Modifier and TypeMethodDescriptionReturns a short human-readable description of this spec.static Optional<RsaSigSpec> fromSignatureAlgorithmId(String algorithmId) Resolves a standard external signature algorithm identifier to an explicit RSA signature specification.hash()Returns the hash algorithm.mode()Returns the signature mode.static RsaSigSpecCreates a PKCS#1 v1.5 spec with the given hash.static RsaSigSpecpss(RsaSigSpec.Hash h, int saltLen) Creates a PSS spec with the given hash and salt length.intReturns the salt length for PSS.
-
Method Details
-
pkcs1v15
Creates a PKCS#1 v1.5 spec with the given hash.- Parameters:
h- hash algorithm- Returns:
- new
RsaSigSpecinstance for PKCS#1 v1.5
-
pss
Creates a PSS spec with the given hash and salt length.A salt length of
-1means “use digest length”, as recommended by PKCS#1.- Parameters:
h- hash algorithmsaltLen- PSS salt length, or -1 for digest length- Returns:
- new
RsaSigSpecinstance for PSS
-
fromSignatureAlgorithmId
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
-
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
Returns a short human-readable description of this spec.Examples:
"PKCS1v1.5(SHA256)""PSS(SHA512,salt=32)""PSS(SHA384,salt=digestLen)"
- Specified by:
descriptionin interfaceDescribable- Returns:
- description string
-