Class ChaChaKeyImportSpec

java.lang.Object
zeroecho.core.alg.chacha.ChaChaKeyImportSpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class ChaChaKeyImportSpec extends Object implements AlgorithmKeySpec, Destroyable

ChaCha20 key import specification

Wraps a raw ChaCha20 key for import into the ZeroEcho framework. Keys must be exactly 32 bytes (256 bits).

Construction

Marshalling

Keys can be serialized/deserialized using PairSeq:

Usage

// Import from raw key bytes
ChaChaKeyImportSpec spec = ChaChaKeyImportSpec.fromRaw(keyBytes);
SecretKey key = cryptoAlgorithm.symmetricKeyImporter(ChaChaKeyImportSpec.class).importSecret(spec);

// Serialize to PairSeq
PairSeq seq = ChaChaKeyImportSpec.marshal(spec);

// Deserialize back
ChaChaKeyImportSpec restored = ChaChaKeyImportSpec.unmarshal(seq);
Since:
1.0
  • Method Details

    • fromRaw

      public static ChaChaKeyImportSpec fromRaw(byte[] key)
      Creates a spec from a raw byte array.
      Parameters:
      key - 32-byte raw key
      Returns:
      spec wrapping the key
    • fromHex

      public static ChaChaKeyImportSpec fromHex(String hex)
      Creates a spec from a hexadecimal string.
      Parameters:
      hex - hex-encoded key
      Returns:
      spec wrapping the decoded key
    • fromBase64

      public static ChaChaKeyImportSpec fromBase64(String b64)
      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

      public static PairSeq marshal(ChaChaKeyImportSpec spec)
      Serializes this spec into a PairSeq, storing the key as Base64.
      Parameters:
      spec - spec to serialize
      Returns:
      serialized key representation
    • unmarshal

      public static ChaChaKeyImportSpec unmarshal(PairSeq p)
      Restores a spec from a serialized PairSeq.

      Recognized fields:

      • k.b64 - Base64 encoding
      • k.hex - hexadecimal string
      • k.raw - raw ISO-8859-1 string
      Parameters:
      p - serialized key representation
      Returns:
      reconstructed spec
      Throws:
      IllegalArgumentException - if none of the recognized fields are present
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Destroyable