All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class IS.hi.logir.cryptonite.Key

java.lang.Object
   |
   +----IS.hi.logir.cryptonite.Key

public abstract class Key
extends Object
implements Serializable, Fingerprintable
This class is the ancestor of classes to hold one public or private key. It's descendants also handle the actual encryption and decryption of data.

Subclasses of Key should be "read-only" in the same sense as the String class and not implement any methods to change the state of the object.

The format of the ciphertext is as follows:

cipher block=<decrypted size><cipher chunk>[cipher chunk[... [cipher chunk]... ]]

Each cipher chunk is a whole number of bytes. The excact number of bytes depends on the key used to encrypt the data.

There may not be enough plain data to fill the last chunk, in which case the last chunk is calculated as if 0's were added to the end of the plaintext.

Author:
Logi Ragnarsson (logir@hi.is)
See Also:
KeyPair, KeyRing

Variable Index

 o fingerprint
The key's MD5 fingerprint.
 o isRegistered
 o keyClasses
 o ONE
The constant one.
 o ownerMail
The key-owner's e-mail address.
 o ownerName
The key-owner's name.
 o primeCertainty
We allow a chance of 0.5**primeCertainty chance that the primes we generate are in fact composite numbers.
 o random
Random is used by descendants of this class to generate random numbers.
 o signatures
The signatures vector may contain certificates for this key.
 o ZERO
The constant zero.

Constructor Index

 o Key(String, String)
Create a new key.

Method Index

 o addKeyClass(String, Class)
Add the class c to the list of available key classes.
 o algorithmName()
Return the name of the algorithm used by this key.
 o blockSize()
Returns a number n, such that least space will be wasted if a mutiple of n bytes is encrypted at once.
 o calcFingerprint()
Return the key's MD5 fingerprint.
 o create(String, int, String, String)
Create a new KeyPair for the named key class with the specified size.
 o decrypt(byte[])
Decrypt the data from source with this key and return an array with the plain bytes.
 o decrypt(Data, Data)
Decrypt the data from source with this key and put the plain data in dest.
 o encrypt(byte[])
Encrypt source with this key and return an array with the encrypted data.
 o encrypt(byte[], int)
Encrypt the first sourceLength bytes of source with this key and return an array with the encrypted data.
 o encrypt(Data, Data)
Encrypt source with this key and put the result in dest.
 o getFingerprint()
Return the key's MD5 fingerprint.
 o getOwnerMail()
Return the e-mail address of the owner.
 o getOwnerName()
Return the name of the owner.
 o getSignatures()
Return an enumeration of this keys certificates.
 o getSize()
Return the "size" of the key.
 o hashCode()
Return a hash-code based on the MD5 fingerprint.
 o matches(Key)
Returns true if this and key are a matched pair of public/private keys.
 o registerIncludedClasses()
Register all the included classes so they can be created by name.
 o toString()
Return a string representation of this key.

Variables

 o keyClasses
 private static Hashtable keyClasses
 o isRegistered
 private static boolean isRegistered
 o random
 public static Random random
Random is used by descendants of this class to generate random numbers. It should be a random number without a period, which rules out all generators based on iterated functions, such as java.util.Random.

If this field is null, an instance of RandomSpinner will be created and used.

See Also:
RandomSpinner
 o primeCertainty
 public static int primeCertainty
We allow a chance of 0.5**primeCertainty chance that the primes we generate are in fact composite numbers.

The default value of 32 will give a false prime less than once in every 4,000,000,000 tries. However, finding one prime often takes several tries, but the likelyhood of a false prime being returned is still negligeble.

 o ONE
 protected static final BigInteger ONE
The constant one.

 o ZERO
 protected static final BigInteger ZERO
The constant zero.

 o ownerName
 private String ownerName
The key-owner's name.

 o ownerMail
 private String ownerMail
The key-owner's e-mail address.

 o fingerprint
 private transient Fingerprint fingerprint
The key's MD5 fingerprint. It is never stored with the key, but re-calculated at run-time. fingerprint may be null in which case it needs to be re-calcualted.

 o signatures
 private Vector signatures
The signatures vector may contain certificates for this key.

Never sign a key unless you have first-hand knowledge that it is valid!

A key which is not certified by a trusted party should not be used.

See Also:
Signature

Constructors

 o Key
 public Key(String ownerName,
            String ownerMail)
Create a new key. It will be marked as belonging to ownerName with e-mail address ownerMail.

Methods

 o addKeyClass
 public static void addKeyClass(String name,
                                Class c)
Add the class c to the list of available key classes. This allows the creation of keys of this class by name.

All regstered classes must be sub-classes of the Key class and implement a static KeyPair createKeys(int size, String ownerName, String ownerMail) method similar to that in the RsaKey class.

See Also:
create, createKeys
 o registerIncludedClasses
 private static void registerIncludedClasses() throws BadKeyClassException
Register all the included classes so they can be created by name.

 o create
 public static KeyPair create(String name,
                              int size,
                              String ownerName,
                              String ownerMail) throws BadKeyClassException
Create a new KeyPair for the named key class with the specified size.

A key class with the specified name must previously have been registered by calling addKeyClass. This is automatically done for those classes included with cryptonite but any other classes must be registered manually.

The meaning of the size parameter depends on the key class. If more than one parameter is needed to fully specify the kind of key to create, a default will be used. If this is not acceptable, use the constructor for the particular key class.

The keys will be marked as belonging to ownerName with e-mail address ownerMail.

See Also:
addKeyClass
 o getSize
 public abstract int getSize()
Return the "size" of the key. This is a measure of how difficult it is to break and is heavily dependant on the algorithm used. In many cases it will be the actual number of bits needed to store the key.

 o getOwnerName
 public final String getOwnerName()
Return the name of the owner.

 o getOwnerMail
 public final String getOwnerMail()
Return the e-mail address of the owner.

 o calcFingerprint
 protected abstract Fingerprint calcFingerprint()
Return the key's MD5 fingerprint.

See Also:
MD5State, Fingerprintable
 o getFingerprint
 public final Fingerprint getFingerprint()
Return the key's MD5 fingerprint.

 o getSignatures
 public Enumeration getSignatures()
Return an enumeration of this keys certificates. These are of the Signature class.

See Also:
Signature
 o algorithmName
 public abstract String algorithmName()
Return the name of the algorithm used by this key.

 o toString
 public String toString()
Return a string representation of this key.

Overrides:
toString in class Object
 o hashCode
 public int hashCode()
Return a hash-code based on the MD5 fingerprint.

Overrides:
hashCode in class Object
 o matches
 public abstract boolean matches(Key key)
Returns true if this and key are a matched pair of public/private keys.

 o blockSize
 public int blockSize()
Returns a number n, such that least space will be wasted if a mutiple of n bytes is encrypted at once.

 o encrypt
 public abstract void encrypt(Data source,
                              Data dest)
Encrypt source with this key and put the result in dest. The source.buf and dest.buf arrays must be different.

 o encrypt
 public final byte[] encrypt(byte source[],
                             int sourceLength)
Encrypt the first sourceLength bytes of source with this key and return an array with the encrypted data. This method ultmately calls encrypt(Data,Data), but causes more memory allocation and garbage collection than using that method directly.

 o encrypt
 public final byte[] encrypt(byte source[])
Encrypt source with this key and return an array with the encrypted data. This method ultmately calls encrypt(Data,Data), but causes more memory allocation and garbage collection than using that method directly.

 o decrypt
 public abstract void decrypt(Data source,
                              Data dest)
Decrypt the data from source with this key and put the plain data in dest. The source.buf and dest.buf arrays must be different.

 o decrypt
 public byte[] decrypt(byte source[])
Decrypt the data from source with this key and return an array with the plain bytes. This method ultmately calls decrypt(Data,Data), but causes more memory allocation and garbage collection than using that method directly.


All Packages  Class Hierarchy  This Package  Previous  Next  Index