Class RsaPublicKeySpec

java.lang.Object
zeroecho.core.alg.rsa.RsaPublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class RsaPublicKeySpec extends Object implements AlgorithmKeySpec
Encoded RSA public key specification in X.509 SubjectPublicKeyInfo format.

This spec wraps the DER-encoded X.509 representation of an RSA public key and is used for importing keys into KeyFactory or algorithm builders (see RsaAlgorithm). It provides safe cloning of the encoded form and supports simple marshal/unmarshal via PairSeq.

Usage

// Import an X.509 encoded public key
byte[] x509 = Files.readAllBytes(Path.of("rsa_public.der"));
RsaPublicKeySpec spec = new RsaPublicKeySpec(x509);

// Retrieve encoded form
byte[] encoded = spec.encoded();

// Marshal for storage or transmission
PairSeq seq = RsaPublicKeySpec.marshal(spec);

// Rebuild from serialized representation
RsaPublicKeySpec parsed = RsaPublicKeySpec.unmarshal(seq);

Instances are immutable and defensively copy their input. Although public keys are not secret, encoded values should still be treated as security relevant data and preserved accurately.

Since:
1.0
  • Constructor Details

    • RsaPublicKeySpec

      public RsaPublicKeySpec(byte[] x509)
      Constructs an RSA public key spec from an X.509-encoded key.
      Parameters:
      x509 - DER-encoded X.509 public key; cloned internally
      Throws:
      NullPointerException - if x509 is null
  • Method Details

    • encoded

      public byte[] encoded()
      Returns a clone of the X.509-encoded public key.
      Returns:
      defensive copy of the encoded key
    • marshal

      public static PairSeq marshal(RsaPublicKeySpec spec)
      Marshals this spec to a PairSeq.

      The output sequence contains:

      • type = "RSA-PUB"
      • x509.b64 = <Base64 encoding of X.509 bytes>
      Parameters:
      spec - RSA public key spec
      Returns:
      pair sequence with type and base64-encoded key material
    • unmarshal

      public static RsaPublicKeySpec unmarshal(PairSeq p)
      Reconstructs an RSA public key spec from a marshaled PairSeq.

      Expects an entry x509.b64 containing the Base64-encoded X.509 public key. The type field is ignored for forward compatibility.

      Parameters:
      p - serialized pair sequence
      Returns:
      RSA public key spec with decoded key material
      Throws:
      IllegalArgumentException - if the sequence does not contain a x509.b64 entry