iaik.security.cipher
Class SecretKey

java.lang.Object
  |
  +--javax.crypto.spec.SecretKeySpec
        |
        +--iaik.security.cipher.SecretKey
All Implemented Interfaces:
Key, KeySpec, SecretKey, Serializable

public class SecretKey
extends SecretKeySpec
implements Serializable

This class represents a secret key as used with symmetric algorithms. Applications generally shall use a proper KeyGenerator for generating the requested Secret Key.

Version:
File Revision 19
See Also:
SecretKey, Key, KeyGenerator, Serialized Form

Fields inherited from interface java.security.Key
serialVersionUID
 
Constructor Summary
SecretKey(byte[] key, int off, int len, String algName)
          Creates a SecretKey object from given byte sub-array and algorithm name.
SecretKey(byte[] key, String algName)
          Creates a SecretKey object from given byte array and algorithm name.
SecretKey(SecretKey key)
           
 
Method Summary
 void destroyCriticalData()
          Destroys the critical data of this object.
 boolean equals(Object obj)
          Compares two secret keys.
 String getAlgorithm()
          Returns the name of the key algorithm for this key.
 byte[] getEncoded()
          Returns a copy of the secret key as byte array.
 String getFormat()
          Returns the format name.
 int hashCode()
          Returns a hash code value for this object.
 void setAlgorithm(String algorithm)
          Sets the algorithm name of this secret key.
 String toString()
          Returns a string representation of this SecretKey.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SecretKey

public SecretKey(byte[] key,
                 String algName)
Creates a SecretKey object from given byte array and algorithm name.

This constructor is called from inside a KeyGenerator to create a SecretKey. Applications shall use the KeyGenerator.getInstance and generateKey methods for creating a SecretKey object.

Parameters:
key - the key as byte array
algName - the name of the key algorithm
See Also:
KeyGenerator.getInstance(java.lang.String), KeyGenerator.generateKey()

SecretKey

public SecretKey(byte[] key,
                 int off,
                 int len,
                 String algName)
Creates a SecretKey object from given byte sub-array and algorithm name. Beginning at off, only len bytes of the given key byte array are used for creating the SecretKey.

This constructor is called from inside a KeyGenerator to create a SecretKey. Applications shall use the KeyGenerator.getInstance and generateKey methods for creating a SecretKey object.

Parameters:
key - the key as byte array
algName - the name of the key algorithm
See Also:
KeyGenerator.getInstance(java.lang.String), KeyGenerator.generateKey()

SecretKey

public SecretKey(SecretKey key)
          throws InvalidKeyException
Method Detail

getEncoded

public byte[] getEncoded()
Returns a copy of the secret key as byte array.
Overrides:
getEncoded in class SecretKeySpec
Returns:
a copy of the secret key as byte array

getAlgorithm

public String getAlgorithm()
Returns the name of the key algorithm for this key.
Overrides:
getAlgorithm in class SecretKeySpec
Returns:
the key algorithm name

setAlgorithm

public void setAlgorithm(String algorithm)
Sets the algorithm name of this secret key. Sometimes the algorithm name is not known at creation time. If you, for instance, use a PKCS#12 key material generator, it will create a SecretKey with algorithm name "Raw". In such cases it may be desireable to subesequently change the algorithm name to the actual key algorithm (e.g. "DESede"). This may be required in situations where the JCE framework (e.g. JDK 1.4) does not allow unlimited strength cryptography and so will deny a key with algorithm name "Raw", but accept it with name "DESede".
Parameters:
algorithm - the name of the algorithm for this key

getFormat

public String getFormat()
Returns the format name.
Overrides:
getFormat in class SecretKeySpec
Returns:
"RAW"

destroyCriticalData

public void destroyCriticalData()
Destroys the critical data of this object.

equals

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

toString

public String toString()
Returns a string representation of this SecretKey.
Overrides:
toString in class Object
Returns:
a string giving some information about this secret key

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