Class KyberPublicKeySpec
java.lang.Object
zeroecho.core.alg.kyber.KyberPublicKeySpec
- All Implemented Interfaces:
AlgorithmKeySpec
Specification wrapper for a Kyber (ML-KEM) public key encoded in X.509.
Instances of this class carry an immutable copy of the X.509
SubjectPublicKeyInfo-encoded bytes. They are used with
CryptoAlgorithm key builders to import keys into the
provider’s native representation.
Encoding
- Format: X.509 DER encoding of a Kyber public key (SubjectPublicKeyInfo).
- Stored as a defensive clone to ensure immutability.
- Marshalling/unmarshalling supported via
PairSeqwith Base64 encoding.
Usage
// Import a public key into a CryptoAlgorithm
byte[] x509Bytes = ...; // obtained from storage
KyberPublicKeySpec spec = new KyberPublicKeySpec(x509Bytes);
PublicKey k = kyberAlg.publicKeyImporter(KyberPublicKeySpec.class).importPublic(spec);
// Serialize for persistence
PairSeq seq = KyberPublicKeySpec.marshal(spec);
// Deserialize back
KyberPublicKeySpec restored = KyberPublicKeySpec.unmarshal(seq);
This class is immutable and thread-safe.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionKyberPublicKeySpec(byte[] x509Der) Creates a new spec from X.509-encoded public key bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic PairSeqmarshal(KyberPublicKeySpec spec) Serializes this spec into aPairSequsing Base64 encoding.toString()Returns a diagnostic string for logging and debugging.static KyberPublicKeySpecReconstructs aKyberPublicKeySpecfrom aPairSeq.byte[]x509()Returns a defensive copy of the X.509-encoded public key.
-
Constructor Details
-
KyberPublicKeySpec
public KyberPublicKeySpec(byte[] x509Der) Creates a new spec from X.509-encoded public key bytes.- Parameters:
x509Der- X.509 SubjectPublicKeyInfo DER-encoded public key, not null- Throws:
NullPointerException- ifx509Deris null
-
-
Method Details
-
x509
public byte[] x509()Returns a defensive copy of the X.509-encoded public key.- Returns:
- cloned byte array of X.509 DER encoding
-
marshal
Serializes this spec into aPairSequsing Base64 encoding.The sequence contains:
type=KyberPublicKeyx509.b64= Base64 of X.509 bytes (no padding)
- Parameters:
spec- the spec to marshal- Returns:
- key-value representation suitable for persistence
-
unmarshal
Reconstructs aKyberPublicKeySpecfrom aPairSeq.- Parameters:
p- key-value sequence containing anx509.b64entry- Returns:
- a new spec with decoded X.509 bytes
- Throws:
IllegalArgumentException- if the required field is missing
-
toString
-