Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SecretKeySpec

public class SecretKeySpec
extends Object implements SecretKey, KeySpec, Serializable

java.lang.Object
   ↳ javax.crypto.spec.SecretKeySpec


A key specification for a SecretKey and also a secret key implementation that is provider-independent. It can be used for raw secret keys that can be specified as byte[].

Summary

Inherited constants

From interface javax.crypto.SecretKey
From interface java.security.Key

Public constructors

SecretKeySpec(byte[] key, String algorithm)

Creates a new SecretKeySpec for the specified key data and algorithm name.

SecretKeySpec(byte[] key, int offset, int len, String algorithm)

Creates a new SecretKeySpec for the key data from the specified buffer key starting at offset with length len and the specified algorithm name.

Public methods

boolean equals(Object obj)

Compares the specified object with this SecretKeySpec instance.

String getAlgorithm()

Returns the algorithm name.

byte[] getEncoded()

Returns the encoded form of this secret key.

String getFormat()

Returns the name of the format used to encode the key.

int hashCode()

Returns the hash code of this SecretKeySpec object.

Inherited methods

From class java.lang.Object
From interface java.security.Key

Public constructors

SecretKeySpec

Added in API level 1
SecretKeySpec (byte[] key, 
                String algorithm)

Creates a new SecretKeySpec for the specified key data and algorithm name.

Parameters
key byte: the key data.
algorithm String: the algorithm name.
Throws
IllegalArgumentException if the key data or the algorithm name is null or if the key data is empty.

SecretKeySpec

Added in API level 1
SecretKeySpec (byte[] key, 
                int offset, 
                int len, 
                String algorithm)

Creates a new SecretKeySpec for the key data from the specified buffer key starting at offset with length len and the specified algorithm name.

Parameters
key byte: the key data.
offset int: the offset.
len int: the size of the key data.
algorithm String: the algorithm name.
Throws
IllegalArgumentException if the key data or the algorithm name is null, the key data is empty or offset and len do not specify a valid chunk in the buffer key.
ArrayIndexOutOfBoundsException if offset or len is negative.

Public methods

equals

Added in API level 1
boolean equals (Object obj)

Compares the specified object with this SecretKeySpec instance.

Parameters
obj Object: the object to compare.
Returns
boolean true if the algorithm name and key of both object are equal, otherwise false.

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the algorithm name.

Returns
String the algorithm name.

getEncoded

Added in API level 1
byte[] getEncoded ()

Returns the encoded form of this secret key.

Returns
byte[] the encoded form of this secret key.

getFormat

Added in API level 1
String getFormat ()

Returns the name of the format used to encode the key.

Returns
String the format name "RAW".

hashCode

Added in API level 1
int hashCode ()

Returns the hash code of this SecretKeySpec object.

Returns
int the hash code.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.