Keys
Let’s start with the various classes that support the notion of keys within Java.
The Key Interface
The concept of a key is modeled by the
Key
interface
(java.security.Key
):
- public interface Key extends Serializable
Model the concept of a single key. Because keys must be transferred to and from various entities, all keys must be serializable.
As we discussed in Chapter 8, there might be several algorithms available for generating (and understanding) keys, depending on the particular security providers that are installed in the virtual machine. Hence, the first thing a key needs to be able to tell us is what algorithm generated it:
- public String getAlgorithm( )
Return a string describing the algorithm used to generate this key; this string should be the name of a standard key generation algorithm.
When a key is transferred between two parties, it is usually encoded as a series of bytes; this encoding must follow a format defined for the type of key. Keys are not required to support encoding -- in which case the format of the data transferred between the two parties in a key exchange is either obvious (e.g., simply the serialized data of the key) or specific to a particular implementation. Keys tell us the format they use for encoding their output with this method:
- public String getFormat( )
Return a string describing the format of the encoding the key supports.
The encoded data of the key itself is produced by this method:
- public byte[] getEncoded( )
Return the bytes that make ...
Get Java Security, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.