com.ibm.crypto.fips.provider
Class RSAPadding
- java.lang.Object
-
- com.ibm.crypto.fips.provider.RSAPadding
-
public final class RSAPadding extends java.lang.Object
RSA padding and unpadding. The various PKCS#1 versions can be found in the EMC/RSA Labs web site, which is currently: http://www.emc.com/emc-plus/rsa-labs/index.htm or in the IETF RFCs derived from the above PKCS#1 standards. RFC 2313: v1.5 RFC 2437: v2.0 RFC 3447: v2.1 The format of PKCS#1 v1.5 padding is: 0x00 | BT | PS...PS | 0x00 | data...data where BT is the blocktype (1 or 2). The length of the entire string must be the same as the size of the modulus (i.e. 128 byte for a 1024 bit key). Per spec, the padding string must be at least 8 bytes long. That leaves up to (length of key in bytes) - 11 bytes for the data. OAEP padding was introduced in PKCS#1 v2.0 and is a bit more complicated and has a number of options. We support: . arbitrary hash functions ('Hash' in the specification), MessageDigest implementation must be available . MGF1 as the mask generation function . the empty string as the default value for label L and whatever specified in javax.crypto.spec.OAEPParameterSpec The algorithms (representations) are forwards-compatible: that is, the algorithm described in previous releases are in later releases. However, additional comments/checks/clarifications were added to the later versions based on real-world experience (e.g. stricter v1.5 format checking.) Note: RSA keys should be at least 512 bits long- Since:
- 1.5
-
-
Field Summary
Fields Modifier and Type Field and Description static int
PAD_BLOCKTYPE_1
static int
PAD_BLOCKTYPE_2
static int
PAD_NONE
static int
PAD_OAEP_MGF1
static int
PAD_ZERO
-
Method Summary
Methods Modifier and Type Method and Description static RSAPadding
getInstance(int type, int paddedSize)
Get a RSAPadding instance of the specified type.static RSAPadding
getInstance(int type, int paddedSize, java.security.SecureRandom random)
Get a RSAPadding instance of the specified type.static RSAPadding
getInstance(int type, int paddedSize, java.security.SecureRandom random, javax.crypto.spec.OAEPParameterSpec spec)
Get a RSAPadding instance of the specified type, which must be OAEP.int
getMaxDataSize()
Return the maximum size of the plaintext data that can be processed using this object.byte[]
pad(byte[] data)
Pad the data and return the padded block.byte[]
pad(byte[] data, int ofs, int len)
Pad the data and return the padded block.byte[]
unpad(byte[] padded)
Unpad the padded block and return the data.byte[]
unpad(byte[] padded, int ofs, int len)
Unpad the padded block and return the data.
-
-
-
Field Detail
-
PAD_BLOCKTYPE_1
public static final int PAD_BLOCKTYPE_1
- See Also:
- Constant Field Values
-
PAD_BLOCKTYPE_2
public static final int PAD_BLOCKTYPE_2
- See Also:
- Constant Field Values
-
PAD_NONE
public static final int PAD_NONE
- See Also:
- Constant Field Values
-
PAD_OAEP_MGF1
public static final int PAD_OAEP_MGF1
- See Also:
- Constant Field Values
-
PAD_ZERO
public static final int PAD_ZERO
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static RSAPadding getInstance(int type, int paddedSize) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Get a RSAPadding instance of the specified type. Keys used with this padding must be paddedSize bytes long.- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
getInstance
public static RSAPadding getInstance(int type, int paddedSize, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Get a RSAPadding instance of the specified type. Keys used with this padding must be paddedSize bytes long.- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
getInstance
public static RSAPadding getInstance(int type, int paddedSize, java.security.SecureRandom random, javax.crypto.spec.OAEPParameterSpec spec) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Get a RSAPadding instance of the specified type, which must be OAEP. Keys used with this padding must be paddedSize bytes long.- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
getMaxDataSize
public int getMaxDataSize()
Return the maximum size of the plaintext data that can be processed using this object.
-
pad
public byte[] pad(byte[] data, int ofs, int len) throws javax.crypto.BadPaddingException
Pad the data and return the padded block.- Throws:
javax.crypto.BadPaddingException
-
pad
public byte[] pad(byte[] data) throws javax.crypto.BadPaddingException
Pad the data and return the padded block.- Throws:
javax.crypto.BadPaddingException
-
unpad
public byte[] unpad(byte[] padded, int ofs, int len) throws javax.crypto.BadPaddingException
Unpad the padded block and return the data.- Throws:
javax.crypto.BadPaddingException
-
unpad
public byte[] unpad(byte[] padded) throws javax.crypto.BadPaddingException
Unpad the padded block and return the data.- Throws:
javax.crypto.BadPaddingException
-
-