message
Class Padder

java.lang.Object
  extended by message.Padder

final class Padder
extends java.lang.Object

Adds or removes padding to / from a message (Padding is used to guarantee a constant message length and therefore prevent linkability). Uses a pseudo-random number Generator (SecureRandom) for generating padding.

This class is thread-safe.


Field Summary
private static java.security.SecureRandom secureRandom
          Random number generator for padding.
 
Constructor Summary
private Padder()
          Empty constructor.
 
Method Summary
protected static byte[] addPadding(byte[] data, int desiredLength)
          Increases the size of the bypassed array to desiredLength, filling it's unused space with padding.
protected static byte[] removePadding(byte[] data, int lengthOfUnpaddedData)
          Removes padding from the bypassed array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

secureRandom

private static java.security.SecureRandom secureRandom
Random number generator for padding.

Constructor Detail

Padder

private Padder()
Empty constructor. Never used since all methods are static.

Method Detail

addPadding

protected static byte[] addPadding(byte[] data,
                                   int desiredLength)
Increases the size of the bypassed array to desiredLength, filling it's unused space with padding. If desiredLength is larger than the bypassed array, no actions are performed (since padding is not necessary).

Parameters:
data - Array to be padded to desiredLength.
desiredLength - Desired length of the bypassed array after padding in byte.

removePadding

protected static byte[] removePadding(byte[] data,
                                      int lengthOfUnpaddedData)
Removes padding from the bypassed array. If lengthOfUnpaddedData is smaller than the bypassed array, no actions are performed (since the bypassed array contains no padding).

Parameters:
data - Array with padding.
lengthOfUnpaddedData - Desired length of the bypassed array after removal of padding.