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
-
fingerprint
- The key's MD5 fingerprint.
-
isRegistered
-
-
keyClasses
-
-
ONE
- The constant one.
-
ownerMail
- The key-owner's e-mail address.
-
ownerName
- The key-owner's name.
-
primeCertainty
- We allow a chance of 0.5**primeCertainty chance that the primes we
generate are in fact composite numbers.
-
random
- Random is used by descendants of this class to generate
random numbers.
-
signatures
- The signatures vector may contain certificates for this key.
-
ZERO
- The constant zero.
-
Key(String, String)
- Create a new key.
-
addKeyClass(String, Class)
- Add the class c to the list of available key classes.
-
algorithmName()
- Return the name of the algorithm used by this key.
-
blockSize()
- Returns a number n, such that least space will be wasted if
a mutiple of n bytes is encrypted at once.
-
calcFingerprint()
- Return the key's MD5 fingerprint.
-
create(String, int, String, String)
- Create a new KeyPair for the named key class with the specified size.
-
decrypt(byte[])
- Decrypt the data from source with this key and return an array
with the plain bytes.
-
decrypt(Data, Data)
- Decrypt the data from source with this key and put the plain data
in dest.
-
encrypt(byte[])
-
Encrypt source with this key and return an array with
the encrypted data.
-
encrypt(byte[], int)
- Encrypt the first sourceLength bytes of source with
this key and return an array with the encrypted data.
-
encrypt(Data, Data)
- Encrypt source with this key and put the result in dest.
-
getFingerprint()
- Return the key's MD5 fingerprint.
-
getOwnerMail()
- Return the e-mail address of the owner.
-
getOwnerName()
- Return the name of the owner.
-
getSignatures()
- Return an enumeration of this keys certificates.
-
getSize()
- Return the "size" of the key.
-
hashCode()
- Return a hash-code based on the MD5 fingerprint.
-
matches(Key)
- Returns true if this and key are a matched pair
of public/private keys.
-
registerIncludedClasses()
- Register all the included classes
so they can be created by name.
-
toString()
- Return a string representation of this key.
keyClasses
private static Hashtable keyClasses
isRegistered
private static boolean isRegistered
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
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.
ONE
protected static final BigInteger ONE
- The constant one.
ZERO
protected static final BigInteger ZERO
- The constant zero.
ownerName
private String ownerName
- The key-owner's name.
ownerMail
private String ownerMail
- The key-owner's e-mail address.
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.
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
Key
public Key(String ownerName,
String ownerMail)
- Create a new key. It will be marked as belonging
to ownerName with e-mail address ownerMail.
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
registerIncludedClasses
private static void registerIncludedClasses() throws BadKeyClassException
- Register all the included classes
so they can be created by name.
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
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.
getOwnerName
public final String getOwnerName()
- Return the name of the owner.
getOwnerMail
public final String getOwnerMail()
- Return the e-mail address of the owner.
calcFingerprint
protected abstract Fingerprint calcFingerprint()
- Return the key's MD5 fingerprint.
- See Also:
- MD5State, Fingerprintable
getFingerprint
public final Fingerprint getFingerprint()
- Return the key's MD5 fingerprint.
getSignatures
public Enumeration getSignatures()
- Return an enumeration of this keys certificates. These are of
the Signature class.
- See Also:
- Signature
algorithmName
public abstract String algorithmName()
- Return the name of the algorithm used by this key.
toString
public String toString()
- Return a string representation of this key.
- Overrides:
- toString in class Object
hashCode
public int hashCode()
- Return a hash-code based on the MD5 fingerprint.
- Overrides:
- hashCode in class Object
matches
public abstract boolean matches(Key key)
- Returns true if this and key are a matched pair
of public/private keys.
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.
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.
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.
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.
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.
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