Package javax.crypto.spec
Class SecretKeySpec
java.lang.Object
javax.crypto.spec.SecretKeySpec
- All Implemented Interfaces:
Serializable,Key,KeySpec,SecretKey
public class SecretKeySpec extends Object implements SecretKey, KeySpec, Serializable
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[].- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description SecretKeySpec(byte[] key, int offset, int len, String algorithm)Creates a newSecretKeySpecfor the key data from the specified bufferkeystarting atoffsetwith lengthlenand the specifiedalgorithmname.SecretKeySpec(byte[] key, String algorithm)Creates a newSecretKeySpecfor the specified key data and algorithm name. -
Method Summary
Modifier and Type Method Description booleanequals(Object obj)Compares the specified object with thisSecretKeySpecinstance.StringgetAlgorithm()Returns the algorithm name.byte[]getEncoded()Returns the encoded form of this secret key.StringgetFormat()Returns the name of the format used to encode the key.inthashCode()Returns the hash code of thisSecretKeySpecobject.
-
Constructor Details
-
SecretKeySpec
Creates a newSecretKeySpecfor the specified key data and algorithm name.- Parameters:
key- the key data.algorithm- the algorithm name.- Throws:
IllegalArgumentException- if the key data or the algorithm name is null or if the key data is empty.
-
SecretKeySpec
Creates a newSecretKeySpecfor the key data from the specified bufferkeystarting atoffsetwith lengthlenand the specifiedalgorithmname.- Parameters:
key- the key data.offset- the offset.len- the size of the key data.algorithm- the algorithm name.- Throws:
IllegalArgumentException- if the key data or the algorithm name is null, the key data is empty oroffsetandlendo not specify a valid chunk in the bufferkey.ArrayIndexOutOfBoundsException- ifoffsetorlenis negative.
-
-
Method Details
-
getAlgorithm
Returns the algorithm name.- Specified by:
getAlgorithmin interfaceKey- Returns:
- the algorithm name.
-
getFormat
Returns the name of the format used to encode the key. -
getEncoded
public byte[] getEncoded()Returns the encoded form of this secret key.- Specified by:
getEncodedin interfaceKey- Returns:
- the encoded form of this secret key.
-
hashCode
public int hashCode()Returns the hash code of thisSecretKeySpecobject.- Overrides:
hashCodein classObject- Returns:
- the hash code.
- See Also:
Object.equals(java.lang.Object)
-
equals
Compares the specified object with thisSecretKeySpecinstance.- Overrides:
equalsin classObject- Parameters:
obj- the object to compare.- Returns:
- true if the algorithm name and key of both object are equal, otherwise false.
- See Also:
Object.hashCode()
-