org.logi.crypto.keys
Interface Key

All Known Subinterfaces:
CipherKey, SignatureKey
All Known Implementing Classes:
K, DHKey

public interface Key

This interface is implemented by cryptographic keys of any type. Any actual functionality of the keys is defined in the interfaces derived from Key.

Classes implementing 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.


Overview of Key classes:

Class P-K Key Size Cipher Block Size Signature Notes
CaesarKey no 1 yes 1 no Very weak. Only included as an example.
DESKey no 56 yes 8 no Old US Government standard. Can be broken with exchaustive search.
TriDESKey no 168 yes 8 no Newer US Government standard. Applies DES three times. Slow.
BlowfishKey no <=448 yes 8 no Fast. Free for all use.
RSAKey yes >=256 yes K-1 / K yes Most widely used public-key algorithm. Patented in the USA and Canada.
DHKey yes >=256 yes n/a yes Diffie-Hellman key-exchange and El-Gamal encryption and signatures. Patent expired.
ElGamalKey yes >=256 yes K-1 / 2*K yes Merged into DHKey and deprecated.

Class: The name of the class implementing an algorithm. It will be based on the name of the algorithm.

P-K: Is this a public-key algorithm?

Key Size: The size of the key in bits. In some cases variable.

Cipher: Can this algorithm be used for encryption?

Block Size: The size of the blocks of data which is encrypted at one time with this algorithm. If the resulting ciphertext block is not the same size, its size is also given, separated by a slash. The size may be based on the size of the key, which is denoted by K. All sizes are given in bytes. Thus "K-1 / 2*K" means that the input block size is one byte less than the size of the key, while the output size is twice the size of the key.

Signature: Can this algorithm be used to sign data?


Author:
Logi Ragnarsson (logir@logi.org)
See Also:
CipherKey, SignatureKey

Method Summary
 java.lang.String getAlgorithm()
          Return the name of the algorithm used by this key.
 Fingerprint getFingerprint()
          Return the key's fingerprint using the default hash function.
 Fingerprint getFingerprint(java.lang.String algorithm)
          Return the key's fingerprint using the named hash function.
 int getSize()
          Return the "size" of the key.
 int hashCode()
          Return a hash-code based on the keys SHA1 fingerprint.
 boolean isPrivate()
          Returns true iff this is a private key.
 boolean matches(Key key)
          Check if a key mathces this.
 Fingerprint matchFingerprint()
          Returns the fingerprint of the matching key in the key-pair.
 Fingerprint matchFingerprint(java.lang.String algorithm)
          Returns the fingerprint of the matching key in the key-pair.
 

Method Detail

getSize

public int getSize()
Return the "size" of the key. This is a (fairly inaccurate) measure of how difficult it is to break and is heavily dependant on the algorithm used.

getFingerprint

public Fingerprint getFingerprint()
Return the key's fingerprint using the default hash function.

getFingerprint

public Fingerprint getFingerprint(java.lang.String algorithm)
                           throws InvalidCDSException
Return the key's fingerprint using the named hash function.
Throws:
InvalidCDSException - if the specified hash function is not available.

matchFingerprint

public Fingerprint matchFingerprint()
Returns the fingerprint of the matching key in the key-pair.

matchFingerprint

public Fingerprint matchFingerprint(java.lang.String algorithm)
                             throws InvalidCDSException
Returns the fingerprint of the matching key in the key-pair.
Throws:
InvalidCDSException - if the specified hash function is not available.

getAlgorithm

public java.lang.String getAlgorithm()
Return the name of the algorithm used by this key.

isPrivate

public boolean isPrivate()
Returns true iff this is a private key.

hashCode

public int hashCode()
Return a hash-code based on the keys SHA1 fingerprint.
Overrides:
hashCode in class java.lang.Object

matches

public boolean matches(Key key)
Check if a key mathces this. This is true if this and key are a matched pair of public/private keys or the same symmetric key.


Copyright 1997-2000 Logi Ragnarsson