com.ibm.crypto.fips.provider
Class RSACipher
- java.lang.Object
-
- javax.crypto.CipherSpi
-
- com.ibm.crypto.fips.provider.RSACipher
-
public final class RSACipher extends javax.crypto.CipherSpiRSA cipher implementation. Supports RSA en/decryption and signing/verifying using PKCS#1 v1.5 padding and without padding (raw RSA). Note that raw RSA is supported mostly for completeness and should only be used in rare cases. Objects should be instantiated by calling Cipher.getInstance() using the following algorithm names: . "RSA/ECB/PKCS1Padding" (or "RSA") for PKCS#1 padding. The mode (blocktype) is selected based on the en/decryption mode and public/private key used . "RSA/ECB/NoPadding" for rsa RSA. We only do one RSA operation per doFinal() call. If the application passes more data via calls to update() or doFinal(), we throw an IllegalBlockSizeException when doFinal() is called (see JCE API spec). Bulk encryption using RSA does not make sense and is not standardized. Note: RSA keys should be at least 512 bits long- Since:
- 1.5
-
-
Constructor Summary
Constructors Constructor and Description RSACipher()Verify the JCE framework in the constructor.
-
Method Summary
Methods Modifier and Type Method and Description protected byte[]engineDoFinal(byte[] in, int inOfs, int inLen)protected intengineDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)protected intengineGetBlockSize()protected byte[]engineGetIV()protected intengineGetKeySize(java.security.Key key)protected intengineGetOutputSize(int inputLen)protected java.security.AlgorithmParametersengineGetParameters()protected voidengineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)protected voidengineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)protected voidengineInit(int opmode, java.security.Key key, java.security.SecureRandom random)protected voidengineSetMode(java.lang.String mode)protected voidengineSetPadding(java.lang.String paddingName)protected java.security.KeyengineUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type)protected byte[]engineUpdate(byte[] in, int inOfs, int inLen)protected intengineUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)protected byte[]engineWrap(java.security.Key key)protected byte[]internalDoFinal(byte[] in, int inOfs, int inLen)protected intinternalDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)protected intinternalGetBlockSize()protected byte[]internalGetIV()protected intinternalGetKeySize(java.security.Key key)protected intinternalGetOutputSize(int inputLen)protected java.security.AlgorithmParametersinternalGetParameters()protected voidinternalInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)protected voidinternalInit(int opmode, java.security.Key key, java.security.SecureRandom random)protected voidinternalSetMode(java.lang.String mode)protected voidinternalSetPadding(java.lang.String paddingName)protected java.security.KeyinternalUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type)protected byte[]internalUpdate(byte[] in, int inOfs, int inLen)protected intinternalUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)protected byte[]internalWrap(java.security.Key key)
-
-
-
Constructor Detail
-
RSACipher
public RSACipher()
Verify the JCE framework in the constructor.- Throws:
java.lang.SecurityException- if fails to verify the JCE framework.
-
-
Method Detail
-
engineSetMode
protected void engineSetMode(java.lang.String mode) throws java.security.NoSuchAlgorithmException- Specified by:
engineSetModein classjavax.crypto.CipherSpi- Throws:
java.security.NoSuchAlgorithmException
-
internalSetMode
protected void internalSetMode(java.lang.String mode) throws java.security.NoSuchAlgorithmException- Throws:
java.security.NoSuchAlgorithmException
-
engineSetPadding
protected void engineSetPadding(java.lang.String paddingName) throws javax.crypto.NoSuchPaddingException- Specified by:
engineSetPaddingin classjavax.crypto.CipherSpi- Throws:
javax.crypto.NoSuchPaddingException
-
internalSetPadding
protected void internalSetPadding(java.lang.String paddingName) throws javax.crypto.NoSuchPaddingException- Throws:
javax.crypto.NoSuchPaddingException
-
engineGetBlockSize
protected int engineGetBlockSize()
- Specified by:
engineGetBlockSizein classjavax.crypto.CipherSpi
-
internalGetBlockSize
protected int internalGetBlockSize()
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen)
- Specified by:
engineGetOutputSizein classjavax.crypto.CipherSpi
-
internalGetOutputSize
protected int internalGetOutputSize(int inputLen)
-
engineGetIV
protected byte[] engineGetIV()
- Specified by:
engineGetIVin classjavax.crypto.CipherSpi
-
internalGetIV
protected byte[] internalGetIV()
-
engineGetParameters
protected java.security.AlgorithmParameters engineGetParameters()
- Specified by:
engineGetParametersin classjavax.crypto.CipherSpi
-
internalGetParameters
protected java.security.AlgorithmParameters internalGetParameters()
-
engineInit
protected void engineInit(int opmode, java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException- Specified by:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyException
-
internalInit
protected void internalInit(int opmode, java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException- Throws:
java.security.InvalidKeyException
-
engineInit
protected void engineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException- Specified by:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException- Specified by:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
internalInit
protected void internalInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] in, int inOfs, int inLen)- Specified by:
engineUpdatein classjavax.crypto.CipherSpi
-
internalUpdate
protected byte[] internalUpdate(byte[] in, int inOfs, int inLen)
-
engineUpdate
protected int engineUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)- Specified by:
engineUpdatein classjavax.crypto.CipherSpi
-
internalUpdate
protected int internalUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs)
-
engineDoFinal
protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Specified by:
engineDoFinalin classjavax.crypto.CipherSpi- Throws:
javax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
internalDoFinal
protected byte[] internalDoFinal(byte[] in, int inOfs, int inLen) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Throws:
javax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
engineDoFinal
protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) throws javax.crypto.ShortBufferException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Specified by:
engineDoFinalin classjavax.crypto.CipherSpi- Throws:
javax.crypto.ShortBufferExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
internalDoFinal
protected int internalDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) throws javax.crypto.ShortBufferException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Throws:
javax.crypto.ShortBufferExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
engineWrap
protected byte[] engineWrap(java.security.Key key) throws java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException- Overrides:
engineWrapin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjavax.crypto.IllegalBlockSizeException
-
internalWrap
protected byte[] internalWrap(java.security.Key key) throws java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException- Throws:
java.security.InvalidKeyExceptionjavax.crypto.IllegalBlockSizeException
-
engineUnwrap
protected java.security.Key engineUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException- Overrides:
engineUnwrapin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmException
-
internalUnwrap
protected java.security.Key internalUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException- Throws:
java.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmException
-
engineGetKeySize
protected int engineGetKeySize(java.security.Key key) throws java.security.InvalidKeyException- Overrides:
engineGetKeySizein classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyException
-
internalGetKeySize
protected int internalGetKeySize(java.security.Key key) throws java.security.InvalidKeyException- Throws:
java.security.InvalidKeyException
-
-