public interface Key
extends java.lang.Cloneable, java.io.Externalizable, java.security.Key
An interface for a key, which may be used for encryption or decryption, for generating or verifying signatures, or for generating or verifying MACs.
A key may be a private key, a public key, or a symmetric key.
The code using this API is responsible for erasing any keys it has to when it is done with them to prevent leakage of sensitive key material.
PrivateKey
, PublicKey
, SymmetricKey
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Performs a deep clone of the Key instance.
|
void |
erase()
Erases the sensitive key material of a private or symmetric key, making the key un-usable.
|
java.lang.String |
getAlgorithm()
Returns the algorithm for which this key is primarily used.
|
boolean |
getAllowExport()
If
false , this key's material may not be exported in plaintext; if true , and if the global export flag is true , the key's material may be exported in plaintext. |
int |
getBitLength()
Returns the number of bits required to represent this key's defining key material.
|
byte[] |
getEncoded()
Returns the encoded form of this key.
|
java.lang.String |
getFormat()
Returns the format of this key's encoded form.
|
java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
java.lang.String getFormat()
getFormat
in interface java.security.Key
byte[] getEncoded()
getEncoded
in interface java.security.Key
int getBitLength()
void erase()
Note: After erase()
has been invoked, no other methods of the Key
object are guaranteed to function correctly. In particular, invoking another method after erase()
may result in a NullPointerException
being thrown.
java.lang.Object clone()
boolean getAllowExport()
false
, this key's material may not be exported in plaintext; if true
, and if the global export flag is true
, the key's material may be exported in plaintext.
If plaintext export is not allowed, the key's output methods, such as getEncoded()
will throw a KeyExportException
.
FIPS_140_2.getAllowKeyExport()
, Cipher.wrapKey(oracle.security.crypto.core.PrivateKey)