tribble.crypto
Class SymmetricKey

java.lang.Object
  extended byjavax.crypto.spec.SecretKeySpec
      extended bytribble.crypto.SymmetricKey
All Implemented Interfaces:
java.security.Key, java.security.spec.KeySpec, javax.crypto.SecretKey, java.io.Serializable

public class SymmetricKey
extends javax.crypto.spec.SecretKeySpec
implements java.security.Key, javax.crypto.SecretKey

Symmetric block cipher key.

This base class provides the foundation for keys of cipher (encryption) algorithms having fixed-length blocks and key lengths and which utilize the same (symmetric, secret) initialization key for both encryption and decryption.

Note that none of these methods are synchronized.

Since:
JCE 1.2 / JRE 1.4, 2002-05-26
Version:
API 2, $Revision: 1.1 $ $Date: 2005/06/27 00:24:25 $
Author:
David R. Tribble (david@tribble.com).

Copyright 2005 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

See Also:
SymmetricCipher, BlockCipherSpi, Serialized Form

Field Summary
 
Fields inherited from interface java.security.Key
serialVersionUID
 
Constructor Summary
SymmetricKey(byte[] key, int off, int len, java.lang.String alg)
          Constructor.
SymmetricKey(byte[] key, java.lang.String alg)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Determmine if this key is equal to another object.
protected  void finalize()
          Finalization.
 java.lang.String getAlgorithm()
          Retrieve the name of the cipher that uses this key.
 byte[] getEncoded()
          Retrieve the raw contents of this key.
 int hashCode()
          Determmine the hash code for this key.
 
Methods inherited from class javax.crypto.spec.SecretKeySpec
getFormat
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.security.Key
getFormat
 

Constructor Detail

SymmetricKey

public SymmetricKey(byte[] key,
                    java.lang.String alg)
Constructor.

Parameters:
key - Raw key contents. A private copy of this array is made, so the contents of key should be wiped after constructing this key in order to protect sensitive information from lingering in memory.
alg - Name of the symmetric cipher algorithm associated with this key.
Since:
1.1, 2005-05-26

SymmetricKey

public SymmetricKey(byte[] key,
                    int off,
                    int len,
                    java.lang.String alg)
Constructor.

Parameters:
key - Raw key contents. A private copy of this array is made, so the contents of key should be wiped after constructing this key in order to protect sensitive information from lingering in memory.
off - Index of the first element in key comprising the key.
len - Number of elements in key comprising the key.
alg - Name of the symmetric cipher algorithm associated with this key.
Since:
1.1, 2005-05-26
Method Detail

equals

public boolean equals(java.lang.Object obj)
Determmine if this key is equal to another object. Symmetric keys with the same raw key contents are equal to each other.

Parameters:
obj - Another object to compare this one to.
Returns:
True if obj is a SymmetricKey and is composed of the same information as this key, otherwise false.
Since:
1.1, 2003-05-26

hashCode

public int hashCode()
Determmine the hash code for this key. Symmetric keys with the same raw key contents have the same hash values.

Returns:
A hash code for this key, derived from its raw key contents.
Since:
1.1, 2003-05-26

getAlgorithm

public java.lang.String getAlgorithm()
Retrieve the name of the cipher that uses this key.

Specified by:
getAlgorithm in interface java.security.Key
Returns:
Name of the cipher algorithm employing this key.
Since:
1.1, 2003-05-26

getEncoded

public byte[] getEncoded()
Retrieve the raw contents of this key.

Specified by:
getEncoded in interface java.security.Key
Returns:
The raw key material comprising this key. Note that a copy of the key is returned, so that any subsequent modifications made to the copy will not affect the actual value of this key.
Since:
1.1, 2003-05-26

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalization.

Throws:
java.lang.Throwable
Since:
1.1, 2005-05-26