Holger's
Java API

com.antelmann.util
Class CipherKey

java.lang.Object
  extended by com.antelmann.util.CipherKey
All Implemented Interfaces:
SynchronousKey

public class CipherKey
extends Object
implements SynchronousKey

CipherKey provides a very easy-to-use, yet effective encryption mechanism. The key (including the password) is transient.

Author:
Holger Antelmann

Field Summary
static String defaultAlgorithm
           
static int defaultIterationCount
           
 
Constructor Summary
CipherKey(char[] password)
           
CipherKey(String pwd)
           
CipherKey(String algorithm, byte[] salt, int iterationCount, char[] password)
           
 
Method Summary
 byte[] decode(byte[] encrypted)
          decodes the given byte array
 void decode(InputStream in, OutputStream out)
           
 String decode(String s)
          convenience method; requires a base64 string
 byte[] encode(byte[] plainSource)
          encodes the given byte array
 void encode(InputStream in, OutputStream out)
           
 String encode(String s)
          convenience method; returns a base64 string
 Cipher getDecoder()
          fully initializes the Cipher for decoding and returns it.
 Cipher getEncoder()
          fully initializes the Cipher for encoding and returns it.
 String getKeySignature()
          returns a signature that is used to identify the key that needs to be known for both, encoding and decoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultIterationCount

public static final int defaultIterationCount
See Also:
Constant Field Values

defaultAlgorithm

public static final String defaultAlgorithm
See Also:
Constant Field Values
Constructor Detail

CipherKey

public CipherKey(String pwd)
          throws GeneralSecurityException
Throws:
GeneralSecurityException

CipherKey

public CipherKey(char[] password)
          throws GeneralSecurityException
Throws:
GeneralSecurityException

CipherKey

public CipherKey(String algorithm,
                 byte[] salt,
                 int iterationCount,
                 char[] password)
          throws GeneralSecurityException
Throws:
GeneralSecurityException
Method Detail

getEncoder

public Cipher getEncoder()
fully initializes the Cipher for encoding and returns it. To be thread-save, operating on the returned Cipher should be synchronized on the returned value.


getDecoder

public Cipher getDecoder()
fully initializes the Cipher for decoding and returns it. To be thread-save, operating on the returned Cipher should be synchronized on the returned value.


encode

public void encode(InputStream in,
                   OutputStream out)
            throws IOException
Throws:
IOException

decode

public void decode(InputStream in,
                   OutputStream out)
            throws IOException
Throws:
IOException

decode

public byte[] decode(byte[] encrypted)
Description copied from interface: SynchronousKey
decodes the given byte array

Specified by:
decode in interface SynchronousKey

encode

public byte[] encode(byte[] plainSource)
Description copied from interface: SynchronousKey
encodes the given byte array

Specified by:
encode in interface SynchronousKey

encode

public String encode(String s)
convenience method; returns a base64 string


decode

public String decode(String s)
              throws RuntimeException
convenience method; requires a base64 string

Throws:
RuntimeException

getKeySignature

public String getKeySignature()
Description copied from interface: SynchronousKey
returns a signature that is used to identify the key that needs to be known for both, encoding and decoding

Specified by:
getKeySignature in interface SynchronousKey


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads