Stay organized with collections
Save and categorize content based on your preferences.
SecretKey
public
interface
SecretKey
implements
Destroyable,
Key
Known indirect subclasses
PBEKey |
The interface to a PBE key.
|
SecretKeySpec |
This class specifies a secret key in a provider-independent fashion.
|
|
A secret (symmetric) key.
The purpose of this interface is to group (and provide type safety
for) all secret key interfaces.
Provider implementations of this interface must overwrite the
equals
and hashCode
methods inherited from
Object
, so that secret keys are compared based on
their underlying key material and not based on reference.
Implementations should override the default destroy
and
isDestroyed
methods from the
Destroyable
interface to enable
sensitive key information to be destroyed, cleared, or in the case
where such information is immutable, unreferenced.
Finally, since SecretKey
is Serializable
, implementations
should also override
ObjectOutputStream.writeObject(java.lang.Object)
to prevent keys that have been destroyed from being serialized.
Keys that implement this interface return the string RAW
as their encoding format (see getFormat
), and return the
raw key bytes as the result of a getEncoded
method call. (The
getFormat
and getEncoded
methods are inherited
from the Key
parent interface.)
Summary
Constants |
long |
serialVersionUID
The class fingerprint that is set to indicate serialization
compatibility since J2SE 1.4.
|
Inherited constants |
From interface
java.security.Key
long |
serialVersionUID
This constant was deprecated
in API level 34.
A serialVersionUID field in an interface is
ineffectual. Do not use; no replacement.
|
|
Inherited methods |
|
From interface
java.security.Key
abstract
String
|
getAlgorithm()
Returns the standard algorithm name for this key.
|
abstract
byte[]
|
getEncoded()
Returns the key in its primary encoding format, or null
if this key does not support encoding.
|
abstract
String
|
getFormat()
Returns the name of the primary encoding format of this key,
or null if this key does not support encoding.
|
|
Constants
serialVersionUID
public static final long serialVersionUID
The class fingerprint that is set to indicate serialization
compatibility since J2SE 1.4.
Constant Value:
-4795878709595146952
(0xbd719db928b8f538)
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# SecretKey\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Constants](#constants) \\| [Inherited Constants](#inhconstants) \\| [Inherited Methods](#inhmethods) \n\nSecretKey\n=========\n\n\n`\npublic\n\n\ninterface\nSecretKey\n`\n\n\n`\n\n\nimplements\n\n`[Destroyable](/reference/javax/security/auth/Destroyable)`,\n\n`[Key](/reference/java/security/Key)`\n\n\n`\n\n|------------------------|\n| javax.crypto.SecretKey |\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [PBEKey](/reference/javax/crypto/interfaces/PBEKey), [SecretKeySpec](/reference/javax/crypto/spec/SecretKeySpec) |-------------------------------------------------------------|----------------------------------------------------------------------| | [PBEKey](/reference/javax/crypto/interfaces/PBEKey) | The interface to a PBE key. | | [SecretKeySpec](/reference/javax/crypto/spec/SecretKeySpec) | This class specifies a secret key in a provider-independent fashion. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA secret (symmetric) key.\nThe purpose of this interface is to group (and provide type safety\nfor) all secret key interfaces.\n\n\nProvider implementations of this interface must overwrite the\n`equals` and `hashCode` methods inherited from\n[Object](/reference/java/lang/Object), so that secret keys are compared based on\ntheir underlying key material and not based on reference.\nImplementations should override the default `destroy` and\n`isDestroyed` methods from the\n[Destroyable](/reference/javax/security/auth/Destroyable) interface to enable\nsensitive key information to be destroyed, cleared, or in the case\nwhere such information is immutable, unreferenced.\nFinally, since `SecretKey` is `Serializable`, implementations\nshould also override\n[ObjectOutputStream.writeObject(java.lang.Object)](/reference/java/io/ObjectOutputStream#writeObject(java.lang.Object))\nto prevent keys that have been destroyed from being serialized.\n\nKeys that implement this interface return the string `RAW`\nas their encoding format (see `getFormat`), and return the\nraw key bytes as the result of a `getEncoded` method call. (The\n`getFormat` and `getEncoded` methods are inherited\nfrom the [Key](/reference/java/security/Key) parent interface.) \n**See also:**\n\n- [SecretKeyFactory](/reference/javax/crypto/SecretKeyFactory)\n- [Cipher](/reference/javax/crypto/Cipher)\n\nSummary\n-------\n\n| ### Constants ||\n|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `long` | [serialVersionUID](/reference/javax/crypto/SecretKey#serialVersionUID) The class fingerprint that is set to indicate serialization compatibility since J2SE 1.4. |\n\n| ### Inherited constants |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| From interface [java.security.Key](/reference/java/security/Key) |--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `long` | [serialVersionUID](/reference/java/security/Key#serialVersionUID) *This constant was deprecated in API level 34. A `serialVersionUID` field in an interface is ineffectual. Do not use; no replacement.* | |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` `[javax.security.auth.Destroyable](/reference/javax/security/auth/Destroyable)` ` |--------------------|--------------------------------------------------------------------------------------------------------------------------------| | ` default void` | ` `[destroy](/reference/javax/security/auth/Destroyable#destroy())`() ` Destroy this `Object`. | | ` default boolean` | ` `[isDestroyed](/reference/javax/security/auth/Destroyable#isDestroyed())`() ` Determine if this `Object` has been destroyed. | ||\n| From interface ` `[java.security.Key](/reference/java/security/Key)` ` |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[String](/reference/java/lang/String) | ` `[getAlgorithm](/reference/java/security/Key#getAlgorithm())`() ` Returns the standard algorithm name for this key. | | ` abstract byte[]` | ` `[getEncoded](/reference/java/security/Key#getEncoded())`() ` Returns the key in its primary encoding format, or null if this key does not support encoding. | | ` abstract `[String](/reference/java/lang/String) | ` `[getFormat](/reference/java/security/Key#getFormat())`() ` Returns the name of the primary encoding format of this key, or null if this key does not support encoding. | ||\n\nConstants\n---------\n\n### serialVersionUID\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static final long serialVersionUID\n```\n\nThe class fingerprint that is set to indicate serialization\ncompatibility since J2SE 1.4.\n\n\u003cbr /\u003e\n\nConstant Value:\n\n-4795878709595146952\n(0xbd719db928b8f538)"]]