javax.crypto.spec
Class SecretKeySpec

java.lang.Object
  |
  +--javax.crypto.spec.SecretKeySpec

public class SecretKeySpec
extends java.lang.Object
implements KeySpec, SecretKey

Secret key specification.


Attention:  This is not a SUN implementation!

This class has been developed by IAIK according to the documentation publicly available.
For SUNīs documentation of this class see http://java.sun.com/security/JCE1.2/spec/apidoc/index.html


This class represents a provider-independent Secret key specification.

A key specification is a transparent representation of the key material constituting the key. To, for instance, specifiy a DES key in provider independent manner, supply the key bytes and request a secret key specification for the DES algorithm, e.g.:

 byte[] keyBytes = ...;
 SecretKeySpec secKeySpec = new SecretKeySpec(keyBytes, "DES");
 

This class does not check if the supplied key material actually will constitute a secret key of type matching to the requested algorithm. For ensuring this, an algorithm-dependent key specification has to be used, e.g.:

 byte[] keyBytes = ...;
 DESKeySpec desKeySpec = new DESKeySpec(keyBytes);
 

See Also:
DESKeySpec, DESedeKeySpec, Serialized Form

Fields inherited from interface java.security.Key
serialVersionUID
 
Constructor Summary
SecretKeySpec(byte[] key, int offset, int len, java.lang.String algorithm)
          Creates a secret key specification for the requested algorithm from the given number of bytes of the supplied byte array, beginning at the given offset.
SecretKeySpec(byte[] key, java.lang.String algorithm)
          Creates a secret key specification for the requested algorithm from the given byte array.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares two SecretKeySpecs.
 java.lang.String getAlgorithm()
          Returns the name of the algorithm associated with this secret key.
 byte[] getEncoded()
          Returns the key material constituting this secret key.
 java.lang.String getFormat()
          Returns the name of the encoding format for this secret key.
 int hashCode()
          Returns a hash code value for this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecretKeySpec

public SecretKeySpec(byte[] key,
                     java.lang.String algorithm)
Creates a secret key specification for the requested algorithm from the given byte array.

This constructor does not check if the supplied key material actually will constitute a secret key of type matching to the requested algorithm. For ensuring this, an algorithm-dependent key specification has to be created, e.g.:

 byte[] keyBytes = ...;
 DESKeySpec desKeySpec = new DESKeySpec(keyBytes);
 

Parameters:
key - the key material constituting the secret key
algorithm - the name of the algorithm for which the secret key shall be created

SecretKeySpec

public SecretKeySpec(byte[] key,
                     int offset,
                     int len,
                     java.lang.String algorithm)
Creates a secret key specification for the requested algorithm from the given number of bytes of the supplied byte array, beginning at the given offset.

This constructor does not check if the supplied key material actually will constitute a secret key of type matching to the requested algorithm. For ensuring this, an algorithm-dependent key specification has to be created, e.g.:

 byte[] keyBytes = ...;
 DESKeySpec desKeySpec = new DESKeySpec(keyBytes, off_set);
 

Parameters:
key - the key material constituting the secret key
offset - the offset the offset indicating the start position within the input key byte array
len - the length of the subarray
algorithm - the name of the algorithm for which the secret key shall be created
Method Detail

getAlgorithm

public java.lang.String getAlgorithm()
Returns the name of the algorithm associated with this secret key.
Returns:
the secret key algorithm

getFormat

public java.lang.String getFormat()
Returns the name of the encoding format for this secret key.
Returns:
the string "RAW"

getEncoded

public byte[] getEncoded()
Returns the key material constituting this secret key.
Returns:
the key material, as byte array

equals

public boolean equals(java.lang.Object obj)
Compares two SecretKeySpecs.
Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this point
Returns:
true if the object to be compared has the same values; false otherwise

hashCode

public int hashCode()
Returns a hash code value for this object.
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object