Package zeroecho.core.alg.chacha
Class ChaChaKeyImportSpec
java.lang.Object
zeroecho.core.alg.chacha.ChaChaKeyImportSpec
- All Implemented Interfaces:
AlgorithmKeySpec
ChaCha20 key import specification
Wraps a raw ChaCha20 key for import into the ZeroEcho framework. Keys must be exactly 32 bytes (256 bits).Construction
fromRaw(byte[])- construct from a raw byte array.fromHex(String)- construct from a hexadecimal string.fromBase64(String)- construct from a Base64 string.
Marshalling
Keys can be serialized/deserialized usingPairSeq:
marshal(ChaChaKeyImportSpec)encodes the key as Base64.unmarshal(PairSeq)accepts fieldsk.b64,k.hex, ork.raw(ISO-8859-1) to restore a spec.
Usage
// Import from raw key bytes
ChaChaKeyImportSpec spec = ChaChaKeyImportSpec.fromRaw(keyBytes);
SecretKey key = cryptoAlgorithm.importSecret(spec);
// Serialize to PairSeq
PairSeq seq = ChaChaKeyImportSpec.marshal(spec);
// Deserialize back
ChaChaKeyImportSpec restored = ChaChaKeyImportSpec.unmarshal(seq);
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic ChaChaKeyImportSpecfromBase64(String b64) Creates a spec from a Base64 string.static ChaChaKeyImportSpecCreates a spec from a hexadecimal string.static ChaChaKeyImportSpecfromRaw(byte[] key) Creates a spec from a raw byte array.byte[]key()Returns a defensive copy of the raw key.static PairSeqmarshal(ChaChaKeyImportSpec spec) Serializes this spec into aPairSeq, storing the key as Base64.static ChaChaKeyImportSpecRestores a spec from a serializedPairSeq.
-
Method Details
-
fromRaw
Creates a spec from a raw byte array.- Parameters:
key- 32-byte raw key- Returns:
- spec wrapping the key
-
fromHex
Creates a spec from a hexadecimal string.- Parameters:
hex- hex-encoded key- Returns:
- spec wrapping the decoded key
-
fromBase64
Creates a spec from a Base64 string.- Parameters:
b64- base64-encoded key- Returns:
- spec wrapping the decoded key
-
key
public byte[] key()Returns a defensive copy of the raw key.- Returns:
- 32-byte key array
-
marshal
Serializes this spec into aPairSeq, storing the key as Base64.- Parameters:
spec- spec to serialize- Returns:
- serialized key representation
-
unmarshal
Restores a spec from a serializedPairSeq.Recognized fields:
k.b64- Base64 encodingk.hex- hexadecimal stringk.raw- raw ISO-8859-1 string
- Parameters:
p- serialized key representation- Returns:
- reconstructed spec
- Throws:
IllegalArgumentException- if none of the recognized fields are present
-