Class DnieCipherImpl
java.lang.Object
javax.crypto.CipherSpi
es.gob.jmulticard.jse.provider.rsacipher.DnieCipherImpl
RSA 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]private byte[]Buffer para los datos.private intNúmero de octetos en el buffer (el offset).private intprivate static final intprivate static final intprivate static final intprivate static final intprivate final StringAlgoritmo de huella para el OAEP.private intTamaño de los datos de salida.private static final StringRSA sin relleno.private static final Stringprivate static final StringRSA con relleno PKCS#1 v1.5.private RSAPaddingprivate Stringprivate RSAPrivateKeyClave privada, si se ha inicializado el cifrador con una clave privada.private RSAPublicKeyLa clave pública, si se ha inicializado el cifrador con una clave pública.private SecureRandomprivate AlgorithmParameterSpec -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]doFinal()protected byte[]engineDoFinal(byte[] inData, int inOfs, int inLen) protected intengineDoFinal(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) protected intprotected byte[]protected intengineGetKeySize(Key key) protected intengineGetOutputSize(int inputLen) protected AlgorithmParametersprotected voidengineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom rnd) protected voidengineInit(int opmode, Key key, SecureRandom rnd) protected voidengineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom rnd) protected voidengineSetMode(String cipherMode) protected voidengineSetPadding(String paddingName) protected KeyengineUnwrap(byte[] wrappedKey, String algorithm, int type) protected byte[]engineUpdate(byte[] inData, int inOfs, int inLen) protected intengineUpdate(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) protected byte[]engineWrap(Key key) private voidinit(int opmode, Key key, SecureRandom rnd, AlgorithmParameterSpec params) Inicializa el cifrador.private voidupdate(byte[] inData, int inOfs, int inLen) Methods inherited from class CipherSpi
engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
-
Field Details
-
B0
private static final byte[] B0 -
MODE_ENCRYPT
private static final int MODE_ENCRYPT- See Also:
-
MODE_DECRYPT
private static final int MODE_DECRYPT- See Also:
-
MODE_SIGN
private static final int MODE_SIGN- See Also:
-
MODE_VERIFY
private static final int MODE_VERIFY- See Also:
-
PAD_NONE
-
PAD_PKCS1
-
PAD_OAEP_MGF1
- See Also:
-
mode
private int mode -
paddingType
-
padding
-
spec
-
buffer
private byte[] bufferBuffer para los datos. -
bufOfs
private int bufOfsNúmero de octetos en el buffer (el offset). -
outputSize
private int outputSizeTamaño de los datos de salida. -
publicKey
La clave pública, si se ha inicializado el cifrador con una clave pública. -
privateKey
Clave privada, si se ha inicializado el cifrador con una clave privada. -
oaepHashAlgorithm
-
random
-
-
Constructor Details
-
DnieCipherImpl
public DnieCipherImpl()Construye un cifrador RSA para el DNIe.
-
-
Method Details
-
engineSetMode
- Specified by:
engineSetModein classCipherSpi- Throws:
NoSuchAlgorithmException
-
engineSetPadding
- Specified by:
engineSetPaddingin classCipherSpi- Throws:
NoSuchPaddingException
-
engineGetBlockSize
protected int engineGetBlockSize()- Specified by:
engineGetBlockSizein classCipherSpi
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen) - Specified by:
engineGetOutputSizein classCipherSpi
-
engineGetIV
protected byte[] engineGetIV()- Specified by:
engineGetIVin classCipherSpi
-
engineGetParameters
- Specified by:
engineGetParametersin classCipherSpi
-
engineInit
- Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom rnd) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyExceptionInvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom rnd) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyExceptionInvalidAlgorithmParameterException
-
init
private void init(int opmode, Key key, SecureRandom rnd, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException Inicializa el cifrador. -
update
private void update(byte[] inData, int inOfs, int inLen) -
doFinal
private byte[] doFinal() throws BadPaddingException, IllegalBlockSizeException, CryptoCardException, PinException, LostChannelException -
engineUpdate
protected byte[] engineUpdate(byte[] inData, int inOfs, int inLen) - Specified by:
engineUpdatein classCipherSpi
-
engineUpdate
protected int engineUpdate(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) - Specified by:
engineUpdatein classCipherSpi
-
engineDoFinal
protected byte[] engineDoFinal(byte[] inData, int inOfs, int inLen) throws BadPaddingException, IllegalBlockSizeException - Specified by:
engineDoFinalin classCipherSpi- Throws:
BadPaddingExceptionIllegalBlockSizeException
-
engineDoFinal
protected int engineDoFinal(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) throws ShortBufferException, BadPaddingException, IllegalBlockSizeException - Specified by:
engineDoFinalin classCipherSpi- Throws:
ShortBufferExceptionBadPaddingExceptionIllegalBlockSizeException
-
engineWrap
- Overrides:
engineWrapin classCipherSpi- Throws:
InvalidKeyExceptionIllegalBlockSizeException
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String algorithm, int type) throws InvalidKeyException, NoSuchAlgorithmException - Overrides:
engineUnwrapin classCipherSpi- Throws:
InvalidKeyExceptionNoSuchAlgorithmException
-
engineGetKeySize
- Overrides:
engineGetKeySizein classCipherSpi- Throws:
InvalidKeyException
-