Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.openpgp.algorithm
Class PGPAlgorithmFactory  view PGPAlgorithmFactory download PGPAlgorithmFactory.java

java.lang.Object
  extended bycryptix.openpgp.algorithm.PGPAlgorithmFactory

public final class PGPAlgorithmFactory
extends java.lang.Object

Factory for public key, string-to-key, compression, hash and cipher algorithms.

In a normal PGP application, the programmer probably does not have to deal with this class that much. The only thing he or she has to do is initialize it with the default values and just use the get methods to translate an algorithm ID into an implementation for that algorithm. The default implementation provides values for all algorithms that are mentioned in RFC2440.

It's real strength however is it's ability to register additional algorithms. For example, once the AES has been chosen (and the maintainer is a bit lazy in adding it), you could just use the registerCipherAlgorithm method to add it yourself.


Field Summary
private  java.util.Hashtable CipherBlockSizes
           
private  java.util.Hashtable CipherKeySizes
           
private  java.util.Hashtable CipherStrings
           
private  java.util.Hashtable CompressionClasses
           
private static int[] defaultCipherBlockSizes
           
private static int[] defaultCipherIDs
           
private static int[] defaultCipherKeySizes
           
private static java.lang.String[] defaultCipherStrings
           
private static java.lang.String[] defaultCompressionClasses
           
private static int[] defaultCompressionIDs
           
private static int[] defaultHashIDs
           
private static java.lang.String[] defaultHashStrings
           
private static java.lang.String[] defaultHashTextNames
           
private static PGPAlgorithmFactory defaultInstance
          Cached default instance
private static java.lang.String[] defaultPublicKeyClasses
           
private static int[] defaultPublicKeyIDs
           
private static java.lang.String[] defaultPublicKeyNames
           
private static java.lang.String[] defaultS2KClasses
           
private static int[] defaultS2KIDs
           
private  java.util.Hashtable HashStrings
           
private  java.util.Hashtable HashTextNames
           
private  java.util.Hashtable HashTextNamesReverse
           
static int INIT_DEFAULT
          Initialize with all default algorithms registered
static int INIT_EMPTY_ALL
          Initialize without any algorithms registered
static int INIT_EMPTY_CIPHER
          Initialize without any cipher algorithms registered
static int INIT_EMPTY_COMPRESSOR
          Initialize without any compression algorithms registered
static int INIT_EMPTY_HASH
          Initialize without any hash algorithms registered
static int INIT_EMPTY_PUBLICKEY
          Initialize without any public key algorithms registered
static int INIT_EMPTY_S2K
          Initialize without any string-to-key algorithms registered
private  java.util.Hashtable PublicKeyClasses
           
private  java.util.Hashtable PublicKeyNames
           
private  java.util.Hashtable S2KClasses
           
 
Constructor Summary
PGPAlgorithmFactory()
          Constructor that initializes all default classes.
PGPAlgorithmFactory(int init)
          Constructor that initializes specific portions.
 
Method Summary
private  void DefaultCipherAlgorithms()
           
private  void DefaultCompressionAlgorithms()
           
private  void DefaultHashAlgorithms()
           
private  void DefaultPublicKeyAlgorithms()
           
private  void DefaultS2KAlgorithms()
           
 javax.crypto.Cipher getCipherAlgorithm(int id, java.lang.String mode)
          Get the cipher algorithm for the specific id
 int getCipherBlockSize(int id)
          Get the cipher block size for the specified id
 int getCipherKeySize(int id)
          Get the cipher key size for the specified id
 PGPCompressor getCompressionAlgorithm(int id)
          Get the compression algorithm for the specific id
static PGPAlgorithmFactory getDefaultInstance()
          Return the default instance of this factory.
 java.security.MessageDigest getHashAlgorithm(int id)
          Get the hash algorithm for the specific id
 int getHashAlgorithmIDFromTextName(java.lang.String str)
          Get the hash algorithm id for a RFC2440 textname of a hashing algorithm This textname is used in the 'Hash:' header of clearsigned messages.
 java.lang.String getHashAlgorithmString(int id)
          Get the name of the hashing algorithm for the specific id
 java.lang.String getHashTextName(int id)
          Get the RFC2440 textname of the hashing algorithm for the specific id This textname is used in the 'Hash:' header of clearsigned messages.
 PGPPublicKeyAlgorithm getPublicKeyAlgorithm(int id)
          Get the public key algorithm for the specific id
 java.lang.String getPublicKeyName(int id)
          Get the name of the public key algorithm for the specific id This name is used in the return values of getAlgorithm() methods.
 PGPStringToKey getS2KAlgorithm(int id)
          Get the string-to-key algorithm for the specific id
 void registerCipherAlgorithm(int id, java.lang.String name, int keysize, int blocksize)
          Register a new cipher algorithm
 void registerCompressionAlgorithm(int id, java.lang.String classname)
          Register a new compression algorithm
 void registerHashAlgorithm(int id, java.lang.String jcename, java.lang.String textname)
          Register a new hash algorithm
 void registerPublicKeyAlgorithm(int id, java.lang.String classname, java.lang.String name)
          Register a new public key algorithm
 void registerS2KAlgorithm(int id, java.lang.String classname)
          Register a new string-to-key algorithm
 void unregisterCipherAlgorithm(int id)
          Unregister an already registered cipher algorithm.
 void unregisterCompressionAlgorithm(int id)
          Unregister an already registered compression algorithm.
 void unregisterHashAlgorithm(int id)
          Unregister an already registered hash algorithm.
 void unregisterPublicKeyAlgorithm(int id)
          Unregister an already registered public key algorithm.
 void unregisterS2KAlgorithm(int id)
          Unregister an already registered string-to-key algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_DEFAULT

public static final int INIT_DEFAULT
Initialize with all default algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_ALL

public static final int INIT_EMPTY_ALL
Initialize without any algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_PUBLICKEY

public static final int INIT_EMPTY_PUBLICKEY
Initialize without any public key algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_CIPHER

public static final int INIT_EMPTY_CIPHER
Initialize without any cipher algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_HASH

public static final int INIT_EMPTY_HASH
Initialize without any hash algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_COMPRESSOR

public static final int INIT_EMPTY_COMPRESSOR
Initialize without any compression algorithms registered

See Also:
Constant Field Values

INIT_EMPTY_S2K

public static final int INIT_EMPTY_S2K
Initialize without any string-to-key algorithms registered

See Also:
Constant Field Values

PublicKeyClasses

private java.util.Hashtable PublicKeyClasses

PublicKeyNames

private java.util.Hashtable PublicKeyNames

CompressionClasses

private java.util.Hashtable CompressionClasses

S2KClasses

private java.util.Hashtable S2KClasses

HashStrings

private java.util.Hashtable HashStrings

HashTextNames

private java.util.Hashtable HashTextNames

HashTextNamesReverse

private java.util.Hashtable HashTextNamesReverse

CipherStrings

private java.util.Hashtable CipherStrings

CipherKeySizes

private java.util.Hashtable CipherKeySizes

CipherBlockSizes

private java.util.Hashtable CipherBlockSizes

defaultPublicKeyIDs

private static final int[] defaultPublicKeyIDs

defaultPublicKeyClasses

private static final java.lang.String[] defaultPublicKeyClasses

defaultPublicKeyNames

private static final java.lang.String[] defaultPublicKeyNames

defaultCompressionIDs

private static final int[] defaultCompressionIDs

defaultCompressionClasses

private static final java.lang.String[] defaultCompressionClasses

defaultS2KIDs

private static final int[] defaultS2KIDs

defaultS2KClasses

private static final java.lang.String[] defaultS2KClasses

defaultHashIDs

private static final int[] defaultHashIDs

defaultHashStrings

private static final java.lang.String[] defaultHashStrings

defaultHashTextNames

private static final java.lang.String[] defaultHashTextNames

defaultCipherIDs

private static final int[] defaultCipherIDs

defaultCipherKeySizes

private static final int[] defaultCipherKeySizes

defaultCipherBlockSizes

private static final int[] defaultCipherBlockSizes

defaultCipherStrings

private static final java.lang.String[] defaultCipherStrings

defaultInstance

private static PGPAlgorithmFactory defaultInstance
Cached default instance

Constructor Detail

PGPAlgorithmFactory

public PGPAlgorithmFactory()
Constructor that initializes all default classes.


PGPAlgorithmFactory

public PGPAlgorithmFactory(int init)
Constructor that initializes specific portions.

The parameter init specifies which algorithms will be registered and which not. Use the constants that start with INIT_ to specify which algorithms should be registerd. For example

// Initialize all default algorithms:
 factory = new PGPAlgorithmFactory(PGPAlgorithmFactory.INIT_DEFAULT);
 // Initialize without any algorithms registered:
 factory = new PGPAlgorithmFactory(PGPAlgorithmFactory.INIT_EMPTY_ALL);
 // Initialize with the default compression and s2k algorithms registered
 // but not he ciphers, hashes and public key algorithms.
 factory = new PGPAlgorithmFactory(
                           PGPAlgorithmFactory.INIT_EMPTY_PUBLICKEY &
                           PGPAlgorithmFactory.INIT_EMPTY_CIPHER &
                           PGPAlgorithmFactory.INIT_EMPTY_HASH);
 

Method Detail

DefaultPublicKeyAlgorithms

private void DefaultPublicKeyAlgorithms()

DefaultCompressionAlgorithms

private void DefaultCompressionAlgorithms()

DefaultS2KAlgorithms

private void DefaultS2KAlgorithms()

DefaultHashAlgorithms

private void DefaultHashAlgorithms()

DefaultCipherAlgorithms

private void DefaultCipherAlgorithms()

getDefaultInstance

public static PGPAlgorithmFactory getDefaultInstance()
Return the default instance of this factory.

Useful when you don't need to do any customization.

This method returns an instance that has been constructed using the INIT_DEFAULT parameter.


registerPublicKeyAlgorithm

public void registerPublicKeyAlgorithm(int id,
                                       java.lang.String classname,
                                       java.lang.String name)
Register a new public key algorithm

If an algorithm is known by multiple ID's, just call this method multiple times with the same classname.


registerCompressionAlgorithm

public void registerCompressionAlgorithm(int id,
                                         java.lang.String classname)
Register a new compression algorithm

If an algorithm is known by multiple ID's, just call this method multiple times with the same classname.


registerS2KAlgorithm

public void registerS2KAlgorithm(int id,
                                 java.lang.String classname)
Register a new string-to-key algorithm

If an algorithm is known by multiple ID's, just call this method multiple times with the same classname.


registerHashAlgorithm

public void registerHashAlgorithm(int id,
                                  java.lang.String jcename,
                                  java.lang.String textname)
Register a new hash algorithm

If an algorithm is known by multiple ID's, just call this method multiple times with the same classname.


registerCipherAlgorithm

public void registerCipherAlgorithm(int id,
                                    java.lang.String name,
                                    int keysize,
                                    int blocksize)
Register a new cipher algorithm

If an algorithm is known by multiple ID's, just call this method multiple times with the same classname.


unregisterPublicKeyAlgorithm

public void unregisterPublicKeyAlgorithm(int id)
Unregister an already registered public key algorithm.

Does nothing if this algorithm wasn't registered in the first place.


unregisterCompressionAlgorithm

public void unregisterCompressionAlgorithm(int id)
Unregister an already registered compression algorithm.

Does nothing if this algorithm wasn't registered in the first place.


unregisterS2KAlgorithm

public void unregisterS2KAlgorithm(int id)
Unregister an already registered string-to-key algorithm.

Does nothing if this algorithm wasn't registered in the first place.


unregisterHashAlgorithm

public void unregisterHashAlgorithm(int id)
Unregister an already registered hash algorithm.

Does nothing if this algorithm wasn't registered in the first place.


unregisterCipherAlgorithm

public void unregisterCipherAlgorithm(int id)
Unregister an already registered cipher algorithm.

Does nothing if this algorithm wasn't registered in the first place.


getPublicKeyAlgorithm

public PGPPublicKeyAlgorithm getPublicKeyAlgorithm(int id)
                                            throws java.security.NoSuchAlgorithmException
Get the public key algorithm for the specific id


getPublicKeyName

public java.lang.String getPublicKeyName(int id)
Get the name of the public key algorithm for the specific id This name is used in the return values of getAlgorithm() methods.


getCompressionAlgorithm

public PGPCompressor getCompressionAlgorithm(int id)
                                      throws java.security.NoSuchAlgorithmException
Get the compression algorithm for the specific id


getS2KAlgorithm

public PGPStringToKey getS2KAlgorithm(int id)
                               throws java.security.NoSuchAlgorithmException
Get the string-to-key algorithm for the specific id


getHashAlgorithm

public java.security.MessageDigest getHashAlgorithm(int id)
                                             throws java.security.NoSuchAlgorithmException
Get the hash algorithm for the specific id


getHashAlgorithmString

public java.lang.String getHashAlgorithmString(int id)
Get the name of the hashing algorithm for the specific id


getHashTextName

public java.lang.String getHashTextName(int id)
Get the RFC2440 textname of the hashing algorithm for the specific id This textname is used in the 'Hash:' header of clearsigned messages.


getHashAlgorithmIDFromTextName

public int getHashAlgorithmIDFromTextName(java.lang.String str)
Get the hash algorithm id for a RFC2440 textname of a hashing algorithm This textname is used in the 'Hash:' header of clearsigned messages.


getCipherAlgorithm

public javax.crypto.Cipher getCipherAlgorithm(int id,
                                              java.lang.String mode)
                                       throws java.security.NoSuchAlgorithmException
Get the cipher algorithm for the specific id


getCipherKeySize

public int getCipherKeySize(int id)
                     throws java.security.NoSuchAlgorithmException
Get the cipher key size for the specified id


getCipherBlockSize

public int getCipherBlockSize(int id)
                       throws java.security.NoSuchAlgorithmException
Get the cipher block size for the specified id