Class NtruPublicKeySpec
java.lang.Object
zeroecho.core.alg.ntru.NtruPublicKeySpec
- All Implemented Interfaces:
AlgorithmKeySpec
NtruPublicKeySpec holds an X.509 SubjectPublicKeyInfo encoded NTRU public key
and supports a simple marshal/unmarshal form.
Instances are immutable. The byte array provided to the constructor is
defensively copied and x509() returns a fresh clone on each call.
Usage
// Construct from existing X.509 bytes
byte[] x509Der = Files.readAllBytes(Path.of("ntru-public.der"));
NtruPublicKeySpec spec = new NtruPublicKeySpec(x509Der);
// Import into JCA (example provider alias shown)
KeyFactory kf = KeyFactory.getInstance("NTRU", "BCPQC");
PublicKey pk = kf.generatePublic(new X509EncodedKeySpec(spec.x509()));
// Marshal to a compact name-value form (Base64 without padding)
PairSeq serialized = NtruPublicKeySpec.marshal(spec);
// Later or elsewhere, reconstruct the spec
NtruPublicKeySpec restored = NtruPublicKeySpec.unmarshal(serialized);
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionNtruPublicKeySpec(byte[] x509Der) Creates a new specification from X.509 SubjectPublicKeyInfo encoded bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic PairSeqmarshal(NtruPublicKeySpec spec) Serializes this specification into a simple name-value sequence.toString()Returns a short diagnostic string including the encoded length.static NtruPublicKeySpecDeserializes a specification from a name-value sequence produced bymarshal(NtruPublicKeySpec).byte[]x509()Returns a copy of the X.509-encoded public key.
-
Constructor Details
-
NtruPublicKeySpec
public NtruPublicKeySpec(byte[] x509Der) Creates a new specification from X.509 SubjectPublicKeyInfo encoded bytes.The input array is not retained. A defensive copy is made and stored.
- Parameters:
x509Der- X.509 DER bytes of the NTRU public key, must not be null- Throws:
NullPointerException- ifx509Deris null
-
-
Method Details
-
x509
public byte[] x509()Returns a copy of the X.509-encoded public key.The returned array is a fresh clone. Callers may modify it without affecting the spec.
- Returns:
- a new byte array containing the X.509 DER encoding
-
marshal
Serializes this specification into a simple name-value sequence.The output contains:
"type"set to"NtruPublicKey"for identification, and"x509.b64"containing the X.509 bytes encoded with Base64 without padding.
- Parameters:
spec- the specification to serialize, must not be null- Returns:
- a
PairSeqcarrying the serialized fields - Throws:
NullPointerException- ifspecis null
-
unmarshal
Deserializes a specification from a name-value sequence produced bymarshal(NtruPublicKeySpec).Fields not recognized by this implementation are ignored to allow forward compatibility. The field
"x509.b64"is required and must contain Base64 (no padding) of the X.509 bytes.- Parameters:
p- the sequence to read- Returns:
- a new specification carrying the decoded X.509 bytes
- Throws:
IllegalArgumentException- if the required"x509.b64"field is absentNullPointerException- ifpis null
-
toString
-