Class RsaEncSpec

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

public final class RsaEncSpec extends Object implements ContextSpec, Describable
Specification of RSA encryption parameters including padding mode, hash function, and optional OAEP label.

This spec is used with RsaCipherContext to configure how RSA encryption and decryption should be performed. It supports two padding schemes:

Construction

Use the static factories to create a spec:
// OAEP with SHA-256
RsaEncSpec oaep = RsaEncSpec.oaep(RsaEncSpec.Hash.SHA256);

// PKCS#1 v1.5
RsaEncSpec pkcs1 = RsaEncSpec.pkcs1v15();

// OAEP with SHA-384 and custom UTF-8 label
RsaEncSpec labeled = RsaEncSpec.oaep(RsaEncSpec.Hash.SHA384)
                               .withLabelUtf8("context");

Instances are immutable. Methods withLabel(byte[]) and withLabelUtf8(String) return new copies with the given label.

Security notes

  • OAEP with SHA-256 or stronger is recommended; PKCS#1 v1.5 is retained only for interoperability and should be avoided for new designs.
  • Labels in OAEP can provide domain separation but are optional; most applications leave them unset.
Since:
1.0
  • Method Details

    • oaep

      public static RsaEncSpec oaep(RsaEncSpec.Hash h)
      Creates an OAEP spec with the given hash function and no label.
      Parameters:
      h - hash function for OAEP
      Returns:
      new RsaEncSpec for OAEP
    • pkcs1v15

      public static RsaEncSpec pkcs1v15()
      Creates a PKCS#1 v1.5 spec.
      Returns:
      new RsaEncSpec for PKCS#1 v1.5
    • withLabel

      public RsaEncSpec withLabel(byte[] l)
      Returns a copy of this spec with the given OAEP label.
      Parameters:
      l - label bytes (cloned); may be null to clear
      Returns:
      new RsaEncSpec with the same padding/hash and new label
    • withLabelUtf8

      public RsaEncSpec withLabelUtf8(String s)
      Returns a copy of this spec with the given UTF-8 OAEP label.
      Parameters:
      s - label string encoded in UTF-8; may be null to clear
      Returns:
      new RsaEncSpec with the same padding/hash and new label
    • padding

      public RsaEncSpec.Padding padding()
      Returns the padding scheme.
      Returns:
      padding scheme
    • hash

      public RsaEncSpec.Hash hash()
      Returns the hash function used in OAEP.
      Returns:
      OAEP hash function, or null if padding is PKCS#1 v1.5
    • label

      public byte[] label()
      Returns the OAEP label as a defensive copy.
      Returns:
      cloned OAEP label, or null if none
    • description

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

      Examples:

      • "PKCS1v1.5"
      • "OAEP(SHA256,label=8B)"
      Specified by:
      description in interface Describable
      Returns:
      description string