This class is extended by classes that provide a general-purpose
padding scheme, such as the ones described in PKCS #5 or in RFC 1423
(PEM).
For simplicity, an assumption is made that padding schemes always
extend the plaintext to the next block boundary. That is, the input
to the padding algorithm always has a length between 0 and
blockSize
-1, and the output always has length
blockSize
.
This class
is not supported in JavaSoft's version of JCE.
Copyright © 1997
Systemics Ltd on behalf of the
Cryptix Development Team.
All rights reserved.
$Revision: 1.8 $
clone
public Object clone()
throws CloneNotSupportedException
Returns a clone of this cipher.
engineGetParameter
protected Object engineGetParameter(String param)
throws NoSuchParameterException,
InvalidParameterException
SPI: Gets the value of the specified algorithm parameter.
This method supplies a general-purpose mechanism through which it is
possible to get the various parameters of this object. A uniform
algorithm-specific naming scheme for each parameter is desirable but
left unspecified at this time.
The default implementation always throws a NoSuchParameterException.
This method
is not supported in JavaSoft's version of JCE.
param
- the string name of the parameter.
- the object that represents the parameter value.
engineIsValidBlockSize
protected boolean engineIsValidBlockSize(int size)
SPI: Returns true if
size is a valid block size (in
bytes) for this scheme.
The default implementation always returns true.
enginePad
protected abstract int enginePad(byte[] in,
int offset,
int length)
SPI: Pads a single incomplete block.
The padding is written to the same buffer that is used for input
(
in). When this method returns, the padded block should be stored at
in[offset .. offset+blockSize-1]
.
in will be long enough to accomodate the padding.
length is
guaranteed to be in the range 0 ..
blockSize
-1.
in
- the buffer containing the incomplete block.offset
- the offset into the in buffer of the block.length
- the number of bytes from the in buffer,
starting at offset, that need to be unpadded.
- the number of padding bytes written.
engineSetBlockSize
protected void engineSetBlockSize(int size)
Sets the
blockSize
variable for this instance.
Subclasses that override this method (to do initialization that
depends on
blockSize
being set) should call
super.engineSetBlockSize(size)
first.
engineSetParameter
protected void engineSetParameter(String param,
Object value)
throws NoSuchParameterException,
InvalidParameterException,
InvalidParameterTypeException
SPI: Sets the specified algorithm parameter to the specified
value.
This method supplies a general-purpose mechanism through which it is
possible to set the various parameters of this object. A uniform
algorithm-specific naming scheme for each parameter is desirable but
left unspecified at this time.
The default implementation always throws a NoSuchParameterException.
This method
is not supported in JavaSoft's version of JCE.
param
- the string name of the parameter.value
- the parameter value.
engineUnpad
protected abstract int engineUnpad(byte[] in,
int offset,
int length)
SPI: Given the specified subarray of bytes that includes
padding bytes, returns the index indicating where padding starts.
length is guaranteed to be a non-negative multiple of
blockSize
.
in
- the buffer containing the bytes.offset
- the offset into the in buffer of the
first byte to be unpadded.length
- the total length in bytes of the blocks to be
unpadded.
- the index into the in buffer indicating
where the padding starts.
getAlgorithm
public final String getAlgorithm()
- the standard name of the padding scheme, such as "PKCS#5".
getAlgorithms
public static String[] getAlgorithms()
Gets the standard names of all PaddingSchemes implemented by any
installed provider. Algorithm names are not duplicated if
they are supported by more than one provider.
The built-in PaddingScheme "NONE" is included.
getAlgorithms
public static String[] getAlgorithms(Provider provider)
Gets the standard names of all PaddingSchemes implemented by a
provider.
getBlockSize
public final int getBlockSize()
Returns the block size for this padding scheme.
getInstance
public static PaddingScheme getInstance(String algorithm)
throws NoSuchAlgorithmException
algorithm
- the standard name or an alias for the algorithm.
- the new PaddingScheme object.
getInstance
public static PaddingScheme getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException,
NoSuchProviderException
Generates a PaddingScheme object implementing the specified
algorithm, as supplied from the specified provider, if such an
algorithm is available from the provider.
See
International JCE Standard Algorithm Names for a list
of PaddingScheme algorithm names.
algorithm
- the standard name or an alias for the algorithm.provider
- the string name of the provider.
- the new KeyGenerator object.
getParameter
public Object getParameter(String param)
throws NoSuchParameterException,
InvalidParameterException
Gets the value of the specified algorithm parameter.
This method supplies a general-purpose mechanism through which it is
possible to get the various parameters of this object. A uniform
algorithm-specific naming scheme for each parameter is desirable but
left unspecified at this time.
This method
is not supported in JavaSoft's version of JCE.
- getParameter in interface Parameterized
param
- the string name of the parameter.
- the object that represents the parameter value.
pad
public final int pad(byte[] in,
int offset,
int length)
Pads a given array of bytes. The padding is written to the same buffer
that is used for input (
in). When this method returns, the padded
output will be stored at
in[offset .. offset+length+padLength(length)-1]
.
The
in array should be long enough to accomodate the padding.
The return value is the number of bytes written,
not the total
length of the padded block.
in
- the buffer containing the input.offset
- the offset of the bytes to be padded.length
- the number of bytes from the in buffer,
starting at offset, that need to be padded.
- the number of padding bytes written to out.
padLength
public final int padLength(int length)
Returns the increase in size that a padding operation would cause on
input data of a given length. This is always
blockSize - (length % blockSize)
.
- padLength in interface Padding
length
- the length of the data to be padded.
- the increase in size that a padding operation would cause on
input of the specified length.
paddingScheme
public final String paddingScheme()
Use getAlgorithm() instead.
- paddingScheme in interface Padding
- the standard name of the padding scheme.
toString
public String toString()
unpad
public final int unpad(byte[] in,
int offset,
int length)
Given the specified subarray of bytes that includes padding bytes,
returns the index indicating where padding starts.
length must be at least
blockSize
.
in
- the buffer containing the bytes.offset
- the offset into the in buffer of the
first byte in the block.length
- the total length in bytes of the blocks to be
unpadded.
- the index into the in buffer indicating where the
padding starts.