Class RsaPublicKeySpec
java.lang.Object
zeroecho.core.alg.rsa.RsaPublicKeySpec
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionRsaPublicKeySpec(byte[] x509) Constructs an RSA public key spec from an X.509-encoded key. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]encoded()Returns a clone of the X.509-encoded public key.static PairSeqmarshal(RsaPublicKeySpec spec) Marshals this spec to aPairSeq.static RsaPublicKeySpecReconstructs an RSA public key spec from a marshaledPairSeq.
-
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- ifx509isnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a clone of the X.509-encoded public key.- Returns:
- defensive copy of the encoded key
-
marshal
Marshals this spec to aPairSeq.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
Reconstructs an RSA public key spec from a marshaledPairSeq.Expects an entry
x509.b64containing the Base64-encoded X.509 public key. Thetypefield 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 ax509.b64entry
-