Package gnu.crypto.pad

Provides a basic API for using block cipher padding algorithms.

Interface Summary

IPad The basic visible methods of any padding algorithm.

Padding algorithms serve to pad and unpad byte arrays usually as the last step in an encryption or respectively a decryption operation.

Class Summary

BasePad An abstract class to facilitate implementing padding algorithms.
PadFactory A Factory to instantiate padding schemes.
PKCS1_V1_5 A padding algorithm implementation of the EME-PKCS1-V1.5 encoding/decoding algorithm as described in section 7.2 of RFC-3447.
PKCS7 The implementation of the PKCS7 padding algorithm.

This algorithm is described for 8-byte blocks in [RFC-1423] and extended to block sizes of up to 256 bytes in [PKCS-7]. References:
RFC-1423: Privacy Enhancement for Internet Electronic Mail: Part III: Algorithms, Modes, and Identifiers.
IETF.

TBC The implementation of the Trailing Bit Complement (TBC) padding algorithm.

In this mode, "...the data string is padded at the trailing end with the complement of the trailing bit of the unpadded message: if the trailing bit is 1, then 0 bits are appended, and if the trailing bit is 0, then 1 bits are appended.

WrongPaddingException A checked exception that indicates that a padding algorithm did not find the expected padding bytes when unpadding some data.
Provides a basic API for using block cipher padding algorithms.

Package overview

A padding scheme is merely a standard method of ensuring that the input to be encrypted is a multiple of the cipher's block size.

The following diagram shows the important classes participating in this package:

../../../../diagrams/pad_class_diag.png" width=296 height=199 border=0>

The following example pads an input buffer, transforms the padded buffer with already-initialized IMode instances, then unpads the output buffer.

IPad padding = IPad.getInstance("PKCS7");
padding.init(blockSize);
byte[] pad = padding.pad(input, 0, input.length);
byte[] pt = new byte[input.length + pad.length];
byte[] ct = new byte[pt.length];
byte[] cpt = new byte[pt.length];
System.arraycopy(input, 0, pt, 0, input.length);
System.arraycopy(pad, 0, pt, input.length, pad.length);
for (int i = 0; i + blockSize <32pt.length; i += blockSize)
{
enc.update(pt, i, ct, i);
}
for (int i = 0; i + blockSize <32ct.length; i += blockSize)
{
dec.update(ct, i, cpt, i);
}
int unpad = padding.unpad(cpt, 0, cpt.length);
byte[] output = new byte[cpt.length - unpad];
System.arraycopy(cpt, 0, output, 0, output.length);
<!-- $Revision: 1.4 $ -->

Copyright © 2001, 2002, 2003
Free Software Foundation, Inc. All Rights Reserved.