javax.crypto.spec

Class SecretKeySpec

public class SecretKeySpec extends Object implements KeySpec, SecretKey

This is a simple wrapper around a raw byte array, for ciphers that do not require any key parameters other than the bytes themselves.

Since this class implements {@link javax.crypto.SecretKey}, which in turn extends {@link java.security.Key}, so instances of this class may be passed directly to the init() methods of {@link javax.crypto.Cipher}.

See Also: SecretKey SecretKeyFactory

Constructor Summary
SecretKeySpec(byte[] key, String algorithm)
Create a new secret key spec from an entire byte array.
SecretKeySpec(byte[] key, int off, int len, String algorithm)
Create a new secret key spec from part of a byte array.
Method Summary
booleanequals(Object o)
StringgetAlgorithm()
Return the name of the algorithm associated with this secret key.
byte[]getEncoded()
Return the key as a byte array.
StringgetFormat()
This key's format, which is always "RAW".
inthashCode()

Constructor Detail

SecretKeySpec

public SecretKeySpec(byte[] key, String algorithm)
Create a new secret key spec from an entire byte array.

Parameters: key The key material. algorithm The name of the algorithm using this key.

SecretKeySpec

public SecretKeySpec(byte[] key, int off, int len, String algorithm)
Create a new secret key spec from part of a byte array.

Parameters: key The key material. off The offset at which key material begins. len The length of key material. algorithm The name of the algorithm using this key.

Method Detail

equals

public boolean equals(Object o)

getAlgorithm

public String getAlgorithm()
Return the name of the algorithm associated with this secret key.

Returns: The algorithm's name.

getEncoded

public byte[] getEncoded()
Return the key as a byte array.

Returns: The key material.

getFormat

public String getFormat()
This key's format, which is always "RAW".

Returns: "RAW"

hashCode

public int hashCode()