Sharkysoft home
Class KeyGenerator


public class KeyGenerator
extends java.lang.Object

Key generation toolbox.

Details: KeyGenerator contains a variety of functions for generating keys.


Constructor Summary
Method Summary
static byte[] compressBits(byte[] ipbSrc, int inSrcLen, byte[] opbDest, int inDestLen)
          Compresses bit vector.
static byte[] getInterleavedHash( iopIn, java.lang.String isAlgorithm, int inMultiplicity)
          Generates extended hash.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public KeyGenerator()
Method Detail


public static byte[] getInterleavedHash( iopIn,
                                        java.lang.String isAlgorithm,
                                        int inMultiplicity)
Generates extended hash.

Details: getInterleavedHash generates an "extended hash" by computing several hashes at once and concatenating them together. The data to be hashed is supplied by iopIn, and the number of simultaneous subhashes to compute is given by inMultiplicity. Each subhash takes its turn drawing bytes, one at a time, from iopIn until it runs out of bytes. The resulting hashes are then concatenated together. The hash function is given by isAlgorithm. Any hash algorithm supported by is supported by this function. For most Java installations, this includes "SHA" and "MD5".

iopIn - the input data
isAlgorithm - the hash function
inMultiplicity - number of simultaneous subhashes
concatenated hash
Throws: - if an I/O error occurs


public static byte[] compressBits(byte[] ipbSrc,
                                  int inSrcLen,
                                  byte[] opbDest,
                                  int inDestLen)
Compresses bit vector.

Details: compressBits compresses the given bit vector (ipbSrc, inSrcLen) into a bit vector of the requested size (inDesLen). The result is stored in the supplied destination array (opbDest), if one is given, or in the return value.

The compression is achieved by linearly mapping each bit in the source vector to the destination vector, by means of the following scaling function:

dest_index = source_index * dest_size / source_size
(using integer arithmatic)

Before the mapping is applied, the destination vector is filled with zeros. Then, for each bit in the source vector that is set to 1, the mapped bit in the destination vector is toggled.

If a destination array is not supplied (i.e., obpDest == null), then one is created automatically and returned.

ibpSrc and opbDest are given in bits, not bytes. Bit zero in ipbSrc is the least significant bit of ipbSrc [inSrcLen - 1]. Similarly, bit zero in opbDest, if supplied, will be the least significant bit of opbDest [inDestLen - 1]. Extra bits in ibpSrc are ignored, and unused bits in opbDest are set to zero.

ipbSrc - the source vector
inSrcLen - length of source vector
obpDest - destination for result
inDestLen - length to compress to
the compressed vector

Sharkysoft home