Class AesKeyImportSpec

java.lang.Object
zeroecho.core.alg.aes.AesKeyImportSpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class AesKeyImportSpec extends Object implements AlgorithmKeySpec, Destroyable
Specification for importing an existing AES key.

This class wraps raw key material (16, 24, or 32 bytes) for use with the AES algorithm. Factory methods support construction from raw bytes, hex strings, or Base64-encoded strings. The key material is defensively copied.

Instances are consumed by the AES key builder to produce a SecretKey.

Objects of this type are thread-safe while active and may be destroyed to wipe their owned key bytes. Access and marshalling fail after destruction.

Since:
1.0
  • Method Details

    • fromRaw

      public static AesKeyImportSpec fromRaw(byte[] key)
      Creates a specification from raw key bytes.
      Parameters:
      key - a 16, 24, or 32 byte array
      Returns:
      an import specification
      Throws:
      IllegalArgumentException - if the length is invalid
    • fromHex

      public static AesKeyImportSpec fromHex(String hex)
      Creates a specification from a hex-encoded string.
      Parameters:
      hex - a string of 32, 48, or 64 hex characters
      Returns:
      an import specification
      Throws:
      NullPointerException - if hex is null
      IllegalArgumentException - if decoded length is invalid
    • fromBase64

      public static AesKeyImportSpec fromBase64(String b64)
      Creates a specification from a Base64-encoded string.
      Parameters:
      b64 - Base64 text without padding
      Returns:
      an import specification
      Throws:
      NullPointerException - if b64 is null
      IllegalArgumentException - if decoded length is invalid
    • key

      public byte[] key()
      Returns a defensive copy of the key bytes.
      Returns:
      the raw key material
    • marshal

      public static PairSeq marshal(AesKeyImportSpec spec)
      Serializes this specification into a key/value sequence, encoding the key in Base64.
      Parameters:
      spec - the specification to marshal
      Returns:
      a sequence containing the key data
    • unmarshal

      public static AesKeyImportSpec unmarshal(PairSeq p)
      Reconstructs a specification from a key/value sequence. Accepts keys under k.b64, k.hex, or k.raw.
      Parameters:
      p - the sequence to parse
      Returns:
      a reconstructed import specification
      Throws:
      IllegalArgumentException - if no key is present
    • destroy

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

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