public class RSACipherProvider
extends java.lang.Object
The RSACipherProvider allows an application to control the RSA cipher
encryption/decryption operations during signature creation/verification for
SignerInfo
objects and the RSA cipher encryption/decryption
(content encryption key encryption/decryption) operations for
RecipientInfo
objects.
To, for instance, use the IAIK PKCS#11 provider for RSA cipher private key based encryption during SignerInfo signature creation only, but the first installed provider for RSA cipher public key based decryption during signature verification you may set the PKCS#11 provider as RSA encryption provider for your SignerInfo object:
IAIKPkcs11 pkcs11Provider = new IAIKPkcs11(); Security.addProvider(pkcs11Provider); ... RSACipherProvider rsaProv = new RSACipherProvider(pkcs11Provider.getName(), null); ... SignerInfo signerInfo = ...; ... signerInfo.setRSACipherProvider(rsaProv);To, for instance, use the IAIK PKCS#11 provider for ReceipientInfo decryption (RSA cipher private key decryption) only, but the first installed provider for encryption (RSA cipher public encryption) you may set the PKCS#11 provider as RSA decryption provider for your RecipientInfo object:
IAIKPkcs11 pkcs11Provider = new IAIKPkcs11(); Security.addProvider(pkcs11Provider); ... RSACipherProvider rsaProv = new RSACipherProvider(null, pkcs11Provider.getName()); ... ReceipientInfo recipientInfo = ...; ... recipientInfo.setRSACipherProvider(rsaProv);In overriding method
cipher
you even
can take more influence on the ciphering process.
The default RSACipherProvider uses the first installed RSA capable crypto provider for RSA en/deciphering.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
cipherDecryptProvider_
Name of the crypto provider to be used for RSA decryption.
|
protected java.lang.String |
cipherEncryptProvider_
Name of the crypto provider to be used for RSA encryption.
|
static int |
DECRYPT_MODE
Cipher decrypt mode.
|
static int |
ENCRYPT_MODE
Cipher encrypt mode.
|
Constructor and Description |
---|
RSACipherProvider()
Default constructor.
|
RSACipherProvider(java.security.Provider cipherEncryptProvider,
java.security.Provider cipherDecryptProvider)
Creates a new RSACipherProvider for the given RSA cipher en/decryption providers.
|
RSACipherProvider(java.lang.String cipherEncryptProvider,
java.lang.String cipherDecryptProvider)
Creates a new RSACipherProvider for the given RSA cipher en/decryption providers.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
cipher(int mode,
java.security.Key key,
byte[] data)
Performs an RSA cipher operation on the supplied data.
|
static RSACipherProvider |
getDefault()
Gets the default RSACipherProvider.
|
void |
setCipherProvider(int cipherMode,
java.security.Provider provider)
Sets the crypto provider to be used for RSA cipher en/decryption providers.
|
void |
setCipherProvider(int cipherMode,
java.lang.String providerName)
Sets the crypto provider to be used for RSA cipher en/decryption providers.
|
static void |
setDefault(RSACipherProvider rsaCipherProvider)
Sets the default RSACipherProvider to be used.
|
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
protected java.lang.String cipherEncryptProvider_
protected java.lang.String cipherDecryptProvider_
public RSACipherProvider()
public RSACipherProvider(java.lang.String cipherEncryptProvider, java.lang.String cipherDecryptProvider)
cipherEncryptProvider
- the name of the crypto provider to be used for RSA encryptioncipherDecryptProvider
- the name of the crypto provider to be used for RSA decryptionpublic RSACipherProvider(java.security.Provider cipherEncryptProvider, java.security.Provider cipherDecryptProvider)
cipherEncryptProvider
- the crypto provider to be used for RSA encryptioncipherDecryptProvider
- the crypto provider to be used for RSA decryptionpublic static void setDefault(RSACipherProvider rsaCipherProvider)
rsaCipherProvider
- the RSACipherProvider to be set as defaultpublic static RSACipherProvider getDefault()
public void setCipherProvider(int cipherMode, java.lang.String providerName) throws java.lang.IllegalArgumentException
cipherMode
- the mode -- ENCRYPT (1) or DECRYPT (2) -- for which to use the given crypto providerproviderName
- the name of the crypto provider to be used for RSA cipher operations according
to the requested modejava.lang.IllegalArgumentException
- if the supplied mode is invalid (only ENCRYPT (1) or DECRYPT (2)
are allowedpublic void setCipherProvider(int cipherMode, java.security.Provider provider) throws java.lang.IllegalArgumentException
cipherMode
- the mode -- ENCRYPT (1) or DECRYPT (2) -- for which to use the given crypto providerprovider
- the crypto provider to be used for RSA cipher operations according
to the requested modejava.lang.IllegalArgumentException
- if the supplied mode is invalid (only ENCRYPT (1) or DECRYPT (2)
are allowedprotected byte[] cipher(int mode, java.security.Key key, byte[] data) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.GeneralSecurityException
mode
- the cipher mode, either ENCRYPT (1) or DECRYPT (2)key
- the key to be useddata
- the data to be en/deciphered:
java.security.NoSuchProviderException
- if any of the crypto providers of this RSACipherProvider is not suitable
for requested operationjava.security.NoSuchAlgorithmException
- if RSA ciphering is not supportedjava.security.InvalidKeyException
- if the supplied key is invalidjava.security.GeneralSecurityException
- if a general security problem occurs