public abstract class Padding
extends java.lang.Object
After initializing
the Padding engine, call method pad
or unpad
for performing a padding or unpadding operation,
respectively:
padding.init(Padding.PAD_MODE, key, modLen, params, random); byte[] paddedMessage = padding.pad(message);respectively
padding.init(Padding.UNPAD_MODE, key, modLen, params, random); byte[] message = padding.unpad(paddingMessage);
Modifier and Type | Field and Description |
---|---|
protected int |
modLen_
The length of the key modulus.
|
protected int |
opMode_
The operation mode; either
PAD_MODE (1) or
UNPAD_MODE (2) |
static java.lang.String |
PADDING_NONE
No padding.
|
static java.lang.String |
PADDING_OAEP
PKCS#1v2.1 OAEP padding.
|
static java.lang.String |
PADDING_PKCS1
PKCS#1v1.5 padding.
|
static java.lang.String |
PADDING_PKCS1_SSL2
PKCS#1v1.5 padding for SSL2.
|
protected java.security.PrivateKey |
privateKey_
The private RSA key.
|
protected java.security.PublicKey |
publicKey_
The public RSA key.
|
Modifier and Type | Method and Description |
---|---|
abstract java.security.AlgorithmParameters |
getParameters() |
void |
init(int paddingMode,
java.security.Key key,
int modLen,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this Padding engine.
|
abstract byte[] |
pad(byte[] data)
Pads the supplied data.
|
abstract byte[] |
unpad(byte[] paddedData)
Unpads the supplied padded data.
|
public static final java.lang.String PADDING_NONE
public static final java.lang.String PADDING_PKCS1
public static final java.lang.String PADDING_PKCS1_SSL2
public static final java.lang.String PADDING_OAEP
protected java.security.PrivateKey privateKey_
protected java.security.PublicKey publicKey_
protected int modLen_
protected int opMode_
PAD_MODE (1)
or
UNPAD_MODE (2)
public void init(int paddingMode, java.security.Key key, int modLen, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
paddingMode
- the padding mode, either PAD_MODE (1)
or
UNPAD_MODE (2)
key
- the en/decryption key; maybe used for checking conformance to the
padding schememodLen
- the length of the key modulusparams
- parameters any parameters required by the padding schemerandom
- generator supplying random numbers if requiredjava.security.InvalidKeyException
- if the key is not appropriate for the padding schemejava.security.InvalidAlgorithmParameterException
- if the parameters are invalid, or the padding mode is invalid
(not PAD_MODE (1)
or
UNPAD_MODE (2)
public abstract java.security.AlgorithmParameters getParameters()
public abstract byte[] pad(byte[] data) throws javax.crypto.BadPaddingException
data
- the data to be paddedjavax.crypto.BadPaddingException
- if an error occurs during padding the datapublic abstract byte[] unpad(byte[] paddedData) throws javax.crypto.BadPaddingException
paddedData
- the data to be unpaddedjavax.crypto.BadPaddingException
- if the padding was invalid