Class RsaPrivateKeySpec
java.lang.Object
zeroecho.core.alg.rsa.RsaPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Encoded RSA private key specification in PKCS#8 format.
This spec wraps the DER-encoded PKCS#8 representation of an RSA private 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 a PKCS#8 encoded key
byte[] pkcs8 = Files.readAllBytes(Path.of("rsa_private.der"));
RsaPrivateKeySpec spec = new RsaPrivateKeySpec(pkcs8);
// Retrieve encoded form
byte[] encoded = spec.encoded();
// Marshal for storage or transmission
PairSeq seq = RsaPrivateKeySpec.marshal(spec);
// Rebuild from serialized representation
RsaPrivateKeySpec parsed = RsaPrivateKeySpec.unmarshal(seq);
Instances defensively copy their input and may be destroyed to wipe the owned encoding. The encoded key material remains sensitive and should be handled with care.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionRsaPrivateKeySpec(byte[] pkcs8) Constructs a new RSA private key spec from a PKCS#8-encoded key. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()byte[]encoded()Returns a clone of the PKCS#8-encoded private key.booleanstatic PairSeqmarshal(RsaPrivateKeySpec spec) Marshals this spec to aPairSeq.static RsaPrivateKeySpecReconstructs an RSA private key spec from a marshaledPairSeq.
-
Constructor Details
-
RsaPrivateKeySpec
public RsaPrivateKeySpec(byte[] pkcs8) Constructs a new RSA private key spec from a PKCS#8-encoded key.- Parameters:
pkcs8- DER-encoded PKCS#8 private key; cloned internally- Throws:
NullPointerException- ifpkcs8isnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a clone of the PKCS#8-encoded private key.- Returns:
- defensive copy of the encoded key
-
marshal
Marshals this spec to aPairSeq.The output sequence contains:
type = "RSA-PRIV"pkcs8.b64 = <Base64 encoding of PKCS#8 bytes>
- Parameters:
spec- RSA private key spec- Returns:
- pair sequence with type and base64-encoded key material
-
unmarshal
Reconstructs an RSA private key spec from a marshaledPairSeq.Expects an entry
pkcs8.b64containing the Base64-encoded PKCS#8 private key. Thetypefield is ignored for forward compatibility.- Parameters:
p- serialized pair sequence- Returns:
- RSA private key spec with decoded key material
- Throws:
IllegalArgumentException- if the sequence does not contain apkcs8.b64entry
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-