Class NullKey
- All Implemented Interfaces:
Serializable, Key
Key representing the intentional absence of cryptographic
key material.
NullKey satisfies APIs that require a Key reference even when
no secret exists (e.g., unkeyed digests or placeholder capabilities). It
contains no sensitive data and is safe to log and share.
Intended uses
- Unkeyed operations such as
DIGESTroles where keys are semantically undefined but aKeyparameter is part of a common interface. - Testing and scaffolding where a non-null
Keyis required to exercise type and flow without provisioning secrets. - Metadata publication for capabilities that don’t depend on key material.
Security properties
- Contains no secret;
getEncoded()returns an empty byte array. - Algorithm and format are the literal string
"NONE". - All instances are equal by type; prefer the
INSTANCEsingleton.
Thread-safety
Immutable; the singleton instance is safe to reuse across threads.- Since:
- 1.0
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this object to another for equality.Returns the algorithm identifier for this sentinel key.byte[]Returns the key in its primary encoding.Returns the primary encoding format for this sentinel key.inthashCode()Returns a stable hash code consistent withequals(Object).toString()Returns a diagnostic string for logs and debugging.
-
Field Details
-
INSTANCE
Singleton instance for all uses where aKeyis required but no key exists.Use this constant rather than constructing new instances. Equality for
NullKeyis defined by type, so all instances compare equal; the singleton avoids unnecessary allocations and clarifies intent.
-
-
Method Details
-
getAlgorithm
Returns the algorithm identifier for this sentinel key.The value is the literal string
"NONE"to signal that no real cryptographic algorithm is associated with this key.- Specified by:
getAlgorithmin interfaceKey- Returns:
- the string
"NONE"
-
getFormat
Returns the primary encoding format for this sentinel key.The value is the literal string
"NONE";getEncoded()returns an empty byte array. -
getEncoded
public byte[] getEncoded()Returns the key in its primary encoding.For
NullKey, this is an empty byte array because no material exists. Callers MAY rely on this to avoid special-casing unkeyed flows.- Specified by:
getEncodedin interfaceKey- Returns:
- a new zero-length byte array
-
equals
Compares this object to another for equality.All
NullKeyinstances are considered equal regardless of identity; equality is defined by type rather than state. Prefer comparing againstINSTANCEwhen intent matters, but this method ensures generic collections and caches behave as expected. -
hashCode
public int hashCode()Returns a stable hash code consistent withequals(Object).Derived from a fixed class-based token so that all
NullKeyinstances hash identically, matching the type-based equality semantics. -
toString
-