javax.crypto.spec
Class SecretKeySpec

java.lang.Object
  |
  +--javax.crypto.spec.SecretKeySpec
All Implemented Interfaces:
Key, KeySpec, SecretKey, Serializable
Direct Known Subclasses:
SecretKey

public class SecretKeySpec
extends 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);
 

Version:
File Revision 19
See Also:
DESKeySpec, DESedeKeySpec, Serialized Form

Fields inherited from interface java.security.Key
serialVersionUID
 
Constructor Summary
SecretKeySpec(byte[] key, int offset, int len, 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, String algorithm)
          Creates a secret key specification for the requested algorithm from the given byte array.
 
Method Summary
 boolean equals(Object obj)
          Compares two SecretKeySpecs.
 String getAlgorithm()
          Returns the name of the algorithm associated with this secret key.
 byte[] getEncoded()
          Returns the key material constituting this secret key.
 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,
                     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,
                     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 String getAlgorithm()
Returns the name of the algorithm associated with this secret key.
Specified by:
getAlgorithm in interface Key
Returns:
the secret key algorithm

getFormat

public String getFormat()
Returns the name of the encoding format for this secret key.
Specified by:
getFormat in interface Key
Returns:
the string "RAW"

getEncoded

public byte[] getEncoded()
Returns the key material constituting this secret key.
Specified by:
getEncoded in interface Key
Returns:
the key material, as byte array

equals

public boolean equals(Object obj)
Compares two SecretKeySpecs.
Overrides:
equals in class 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 Object
Returns:
a hash code value for this object

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK