Class DnieCipherImpl
- java.lang.Object
-
- javax.crypto.CipherSpi
-
- es.gob.jmulticard.jse.provider.rsacipher.DnieCipherImpl
-
public final class DnieCipherImpl 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
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]B0private byte[]bufferBuffer para los datos.private intbufOfsNúmero de octetos en el buffer (el offset).private intmodeprivate static intMODE_DECRYPTprivate static intMODE_ENCRYPTprivate static intMODE_SIGNprivate static intMODE_VERIFYprivate java.lang.StringoaepHashAlgorithmAlgoritmo de huella para el OAEP.private intoutputSizeTamaño de los datos de salida.private static java.lang.StringPAD_NONERSA sin relleno.private static java.lang.StringPAD_OAEP_MGF1private static java.lang.StringPAD_PKCS1RSA con relleno PKCS#1 v1.5.private RSAPaddingpaddingprivate java.lang.StringpaddingTypeprivate java.security.interfaces.RSAPrivateKeyprivateKeyClave privada, si se ha inicializado el cifrador con una clave privada.private java.security.interfaces.RSAPublicKeypublicKeyLa clave pública, si se ha inicializado el cifrador con una clave pública.private java.security.SecureRandomrandomprivate java.security.spec.AlgorithmParameterSpecspec
-
Constructor Summary
Constructors Constructor Description DnieCipherImpl()Construye un cifrador RSA para el DNIe.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]doFinal()protected byte[]engineDoFinal(byte[] inData, int inOfs, int inLen)protected intengineDoFinal(byte[] inData, 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.AlgorithmParameters params, java.security.SecureRandom rnd)protected voidengineInit(int opmode, java.security.Key key, java.security.SecureRandom rnd)protected voidengineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom rnd)protected voidengineSetMode(java.lang.String cipherMode)protected voidengineSetPadding(java.lang.String paddingName)protected java.security.KeyengineUnwrap(byte[] wrappedKey, java.lang.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(java.security.Key key)private voidinit(int opmode, java.security.Key key, java.security.SecureRandom rnd, java.security.spec.AlgorithmParameterSpec params)Inicializa el cifrador.private voidupdate(byte[] inData, int inOfs, int inLen)
-
-
-
Field Detail
-
B0
private static final byte[] B0
-
MODE_ENCRYPT
private static final int MODE_ENCRYPT
- See Also:
- Constant Field Values
-
MODE_DECRYPT
private static final int MODE_DECRYPT
- See Also:
- Constant Field Values
-
MODE_SIGN
private static final int MODE_SIGN
- See Also:
- Constant Field Values
-
MODE_VERIFY
private static final int MODE_VERIFY
- See Also:
- Constant Field Values
-
PAD_NONE
private static final java.lang.String PAD_NONE
RSA sin relleno.- See Also:
- Constant Field Values
-
PAD_PKCS1
private static final java.lang.String PAD_PKCS1
RSA con relleno PKCS#1 v1.5.- See Also:
- Constant Field Values
-
PAD_OAEP_MGF1
private static final java.lang.String PAD_OAEP_MGF1
- See Also:
- Constant Field Values
-
mode
private int mode
-
paddingType
private java.lang.String paddingType
-
padding
private RSAPadding padding
-
spec
private java.security.spec.AlgorithmParameterSpec spec
-
buffer
private byte[] buffer
Buffer para los datos.
-
bufOfs
private int bufOfs
Número de octetos en el buffer (el offset).
-
outputSize
private int outputSize
Tamaño de los datos de salida.
-
publicKey
private java.security.interfaces.RSAPublicKey publicKey
La clave pública, si se ha inicializado el cifrador con una clave pública.
-
privateKey
private java.security.interfaces.RSAPrivateKey privateKey
Clave privada, si se ha inicializado el cifrador con una clave privada.
-
oaepHashAlgorithm
private final java.lang.String oaepHashAlgorithm
Algoritmo de huella para el OAEP.- See Also:
- Constant Field Values
-
random
private java.security.SecureRandom random
-
-
Method Detail
-
engineSetMode
protected void engineSetMode(java.lang.String cipherMode) throws java.security.NoSuchAlgorithmException- Specified by:
engineSetModein classjavax.crypto.CipherSpi- 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
-
engineGetBlockSize
protected int engineGetBlockSize()
- Specified by:
engineGetBlockSizein classjavax.crypto.CipherSpi
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen)
- Specified by:
engineGetOutputSizein classjavax.crypto.CipherSpi
-
engineGetIV
protected byte[] engineGetIV()
- Specified by:
engineGetIVin classjavax.crypto.CipherSpi
-
engineGetParameters
protected java.security.AlgorithmParameters engineGetParameters()
- Specified by:
engineGetParametersin classjavax.crypto.CipherSpi
-
engineInit
protected void engineInit(int opmode, java.security.Key key, java.security.SecureRandom rnd) throws java.security.InvalidKeyException- Specified by:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyException
-
engineInit
protected void engineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom rnd) 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 rnd) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException- Specified by:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
init
private void init(int opmode, java.security.Key key, java.security.SecureRandom rnd, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInicializa el cifrador.- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
update
private void update(byte[] inData, int inOfs, int inLen)
-
doFinal
private byte[] doFinal() throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, CryptoCardException, PinException, LostChannelException- Throws:
javax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionCryptoCardExceptionPinExceptionLostChannelException
-
engineUpdate
protected byte[] engineUpdate(byte[] inData, int inOfs, int inLen)- Specified by:
engineUpdatein classjavax.crypto.CipherSpi
-
engineUpdate
protected int engineUpdate(byte[] inData, int inOfs, int inLen, byte[] out, int outOfs)- Specified by:
engineUpdatein classjavax.crypto.CipherSpi
-
engineDoFinal
protected byte[] engineDoFinal(byte[] inData, int inOfs, int inLen) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Specified by:
engineDoFinalin classjavax.crypto.CipherSpi- Throws:
javax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
engineDoFinal
protected int engineDoFinal(byte[] inData, 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
-
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
-
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
-
engineGetKeySize
protected int engineGetKeySize(java.security.Key key) throws java.security.InvalidKeyException- Overrides:
engineGetKeySizein classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyException
-
-