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 int
Número de octetos en el buffer (el offset).private int
private static final int
private static final int
private static final int
private static final int
private final String
Algoritmo de huella para el OAEP.private int
Tamaño de los datos de salida.private static final String
RSA sin relleno.private static final String
private static final String
RSA con relleno PKCS#1 v1.5.private RSAPadding
private String
private RSAPrivateKey
Clave privada, si se ha inicializado el cifrador con una clave privada.private RSAPublicKey
La clave pública, si se ha inicializado el cifrador con una clave pública.private SecureRandom
private AlgorithmParameterSpec
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
doFinal()
protected byte[]
engineDoFinal
(byte[] inData, int inOfs, int inLen) protected int
engineDoFinal
(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) protected int
protected byte[]
protected int
engineGetKeySize
(Key key) protected int
engineGetOutputSize
(int inputLen) protected AlgorithmParameters
protected void
engineInit
(int opmode, Key key, AlgorithmParameters params, SecureRandom rnd) protected void
engineInit
(int opmode, Key key, SecureRandom rnd) protected void
engineInit
(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom rnd) protected void
engineSetMode
(String cipherMode) protected void
engineSetPadding
(String paddingName) protected Key
engineUnwrap
(byte[] wrappedKey, String algorithm, int type) protected byte[]
engineUpdate
(byte[] inData, int inOfs, int inLen) protected int
engineUpdate
(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) protected byte[]
engineWrap
(Key key) private void
init
(int opmode, Key key, SecureRandom rnd, AlgorithmParameterSpec params) Inicializa el cifrador.private void
update
(byte[] inData, int inOfs, int inLen) Methods inherited from class javax.crypto.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
RSA sin relleno.- See Also:
-
PAD_PKCS1
RSA con relleno PKCS#1 v1.5.- See Also:
-
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
Algoritmo de huella para el OAEP.- See Also:
-
random
-
-
Constructor Details
-
DnieCipherImpl
public DnieCipherImpl()Construye un cifrador RSA para el DNIe.
-
-
Method Details
-
engineSetMode
- Specified by:
engineSetMode
in classCipherSpi
- Throws:
NoSuchAlgorithmException
-
engineSetPadding
- Specified by:
engineSetPadding
in classCipherSpi
- Throws:
NoSuchPaddingException
-
engineGetBlockSize
protected int engineGetBlockSize()- Specified by:
engineGetBlockSize
in classCipherSpi
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen) - Specified by:
engineGetOutputSize
in classCipherSpi
-
engineGetIV
protected byte[] engineGetIV()- Specified by:
engineGetIV
in classCipherSpi
-
engineGetParameters
- Specified by:
engineGetParameters
in classCipherSpi
-
engineInit
- Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom rnd) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom rnd) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
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:
engineUpdate
in classCipherSpi
-
engineUpdate
protected int engineUpdate(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) - Specified by:
engineUpdate
in classCipherSpi
-
engineDoFinal
protected byte[] engineDoFinal(byte[] inData, int inOfs, int inLen) throws BadPaddingException, IllegalBlockSizeException - Specified by:
engineDoFinal
in classCipherSpi
- Throws:
BadPaddingException
IllegalBlockSizeException
-
engineDoFinal
protected int engineDoFinal(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs) throws ShortBufferException, BadPaddingException, IllegalBlockSizeException - Specified by:
engineDoFinal
in classCipherSpi
- Throws:
ShortBufferException
BadPaddingException
IllegalBlockSizeException
-
engineWrap
- Overrides:
engineWrap
in classCipherSpi
- Throws:
InvalidKeyException
IllegalBlockSizeException
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String algorithm, int type) throws InvalidKeyException, NoSuchAlgorithmException - Overrides:
engineUnwrap
in classCipherSpi
- Throws:
InvalidKeyException
NoSuchAlgorithmException
-
engineGetKeySize
- Overrides:
engineGetKeySize
in classCipherSpi
- Throws:
InvalidKeyException
-