- All Implemented Interfaces:
AutoCloseable
,Cloneable
,Destroyable
- Direct Known Subclasses:
UnprotectedKey
byte[]
as a matter of both convenience and protection.
This does not provide any access to the given key. It is a key black hole: gone forever from outside observers. The only way a key is available is through a newly generated key.
Instances of this class are thread-safe.
This class intentionally does not implement equals(java.lang.Object)
and hashCode()
, as it is not
intended to be used in data structures or any complex manipulation. It is solely meant to safely carry a
key.
This class also does not implement Serializable
or Externalizable
. Applications that need to send
keys across the wire must use another mechanism. Applications that need to store keys should be using
HashedKey
.
- Author:
- AO Industries, Inc.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
void
close()
Destroys the key on auto-close.void
destroy()
boolean
int
hashCode()
Uses default implementation fromObject.hashCode()
.boolean
toString()
valueOf
(byte[] key) Gets a new key orOptional.empty()
whenkey == null || key.length == 0
.
-
Constructor Details
-
Key
- Parameters:
key
- Is zeroed before this method returns. If the original key is needed, pass a copy to this method.- Throws:
IllegalArgumentException
- whenkey == null || key.length == 0
or whenkey
is already destroyed (contains all zeroes).- See Also:
-
-
Method Details
-
valueOf
Gets a new key orOptional.empty()
whenkey == null || key.length == 0
.- Parameters:
key
- Is zeroed before this method returns. If the original key is needed, pass a copy to this method.- Throws:
IllegalArgumentException
- whenkey
is already destroyed (contains all zeroes).- See Also:
-
toString
-
equals
-
hashCode
public int hashCode()Uses default implementation fromObject.hashCode()
. Any meaningful implementation could leak private key information. UseUnprotectedKey
instead when needing to use in hash-based data structures. -
clone
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyed
in interfaceDestroyable
-
close
public void close()Destroys the key on auto-close. This use for support of try-with-resources.- Specified by:
close
in interfaceAutoCloseable
-