public class RSA extends RSACipher
RSACipher| Modifier and Type | Field and Description |
|---|---|
static int |
DECRYPT_MODE
Cipher decryption mode.
|
static int |
ENCRYPT_MODE
Cipher encryption mode.
|
| Modifier | Constructor and Description |
|---|---|
protected |
RSA()
Default Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected byte[] |
doFinal(byte[] in,
int inOff,
int inLen)
Performs a modulo exponentiation.
|
java.security.SecureRandom |
getSecureRandom()
Gets the SecureRandom used by this Signature engine.
|
protected void |
init(int opmode,
java.security.Key key,
java.security.SecureRandom random)
Initializes this RSA cipher with the given key.
|
protected void |
setMode(java.lang.String mode)
Sets the block mode of the encryption block according to PKCS#1.
|
protected void |
setPadding(java.lang.String padding)
Sets the padding scheme of this cipher.
|
static void |
setRSACipherFactory(RSACipherFactory factory)
Sets the RSA Cipher factory.
|
void |
setSecureRandom(java.security.SecureRandom random)
Sets the SecureRandom to be used by this Signature engine.
|
engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUnwrap, engineUpdate, engineUpdate, engineWrap, isUseBlinding, isUseBlindingDefault, rawCrypt, rawPrivateRSA, rawPublicRSA, setUseBlinding, setUseBlindingDefault, setValidateAgainstOaepKeyParameterspublic static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
public static void setRSACipherFactory(RSACipherFactory factory)
RSACipherFactory set by this
method to get a RSA
cipher object when required for RSA based en/decryption operations.
// custom RSA cipher implementation
class MyRSACipherImpl extends RSA {
...
}
public class MyRSACipherFactory implements RSACipherFactory {
public RSACipherFactory() {
}
public RSA getInstance() {
return new MyRSACipherImpl();
}
}
// Now tell the RSA Signature library to use the custom RSACiperFactory:
RSA.setRSACipherFactory(new MyRSACipherFactory());
factory - the RSACipherFactory to be usedprotected void init(int opmode,
java.security.Key key,
java.security.SecureRandom random)
throws java.security.InvalidKeyException
Before a cipher object is ready for data processing, it has to be initialized
according to the desired cryptographic operation, which is specified by the
opmode parameter (either ENCRYPT_MODE or DECRYPT_MODE).
The key either will be a RSAPrivateKey or a RSAPublicKey, depending on
the specific cryptographic operation to be performed.
This class supports keys represented by IAIK specific classes as well as
java.security.spec.RSA*KeySpec,
java.security.interfaces.RSA*Key,
as well as java.security.PublicKey and java.security.PrivateKey
that ASN.1 code themselves as RSA keys.
opmode - ENCRYPT_MODE or DECRYPT_MODEkey - an instance of a RSA PublicKey or RSA PrivateKeyrandom - source of randomnessjava.security.InvalidKeyException - if the RSA key cannot be createdprotected void setPadding(java.lang.String padding)
throws java.lang.Exception
padding - the padding scheme for this RSA cipherjava.lang.Exception - if the requested padding is not supportedprotected void setMode(java.lang.String mode)
throws java.security.NoSuchAlgorithmException
mode - the block type (0,1 or 2)java.security.NoSuchAlgorithmException - if the block type is not 0,1 or 2protected byte[] doFinal(byte[] in,
int inOff,
int inLen)
throws java.lang.Exception
The data to be processed is given in an input byte array. Beginning at
inputOffset, only the first inputLen bytes are
en/decrypted. The result is returned as an output byte array.
in - the byte array holding the data to be processedinOff - the offset indicating the start position within the input byte arrayinLen - the number of bytes to be processedBadPaddingException - if the decrypted data is not bounded by the proper padding bytes after data
decryption including (un)paddingjava.lang.Exceptionpublic void setSecureRandom(java.security.SecureRandom random)
setSecureRandom in class RSACipherrandom - the SecureRandom to be used by this signature enginepublic java.security.SecureRandom getSecureRandom()
getSecureRandom in class RSACipherSecRandom