Class AesKeyImportSpec
java.lang.Object
zeroecho.core.alg.aes.AesKeyImportSpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
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 Summary
Modifier and TypeMethodDescriptionvoiddestroy()static AesKeyImportSpecfromBase64(String b64) Creates a specification from a Base64-encoded string.static AesKeyImportSpecCreates a specification from a hex-encoded string.static AesKeyImportSpecfromRaw(byte[] key) Creates a specification from raw key bytes.booleanbyte[]key()Returns a defensive copy of the key bytes.static PairSeqmarshal(AesKeyImportSpec spec) Serializes this specification into a key/value sequence, encoding the key in Base64.static AesKeyImportSpecReconstructs a specification from a key/value sequence.
-
Method Details
-
fromRaw
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
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- ifhexis nullIllegalArgumentException- if decoded length is invalid
-
fromBase64
Creates a specification from a Base64-encoded string.- Parameters:
b64- Base64 text without padding- Returns:
- an import specification
- Throws:
NullPointerException- ifb64is nullIllegalArgumentException- if decoded length is invalid
-
key
public byte[] key()Returns a defensive copy of the key bytes.- Returns:
- the raw key material
-
marshal
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
Reconstructs a specification from a key/value sequence. Accepts keys underk.b64,k.hex, ork.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:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-