public class ElGamal
extends javax.crypto.CipherSpi
Constructor and Description |
---|
ElGamal()
Default Constructor for the ELGamal cipher.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen)
En/decrypts the given data.
|
protected int |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
En/decrypts the given data.
|
protected int |
engineGetBlockSize() |
protected byte[] |
engineGetIV()
This method return
null , because this cipher does not use an
IV. |
protected int |
engineGetOutputSize(int inputLen) |
protected java.security.AlgorithmParameters |
engineGetParameters()
Returns the algorithm parameters
|
protected void |
engineInit(int opmode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this ElGamal cipher with given key and algorithm parameters.
|
protected void |
engineInit(int opmode,
java.security.Key key,
java.security.AlgorithmParameters params,
java.security.SecureRandom random)
Initializes this ElGamal cipher with given key and parameters (if
specified).
|
protected void |
engineInit(int opmode,
java.security.Key key,
java.security.SecureRandom random)
Initializes this ElGamal cipher with the given key.
|
protected void |
engineSetMode(java.lang.String mode)
Sets the transformation mode.
|
protected void |
engineSetPadding(java.lang.String padding)
Sets the padding scheme of this cipher, which only can be "PKCS1Padding" or
"NoPadding".
|
protected byte[] |
engineUpdate(byte[] in,
int inOff,
int inLen)
Updates this Cipher with the given bytes.
|
protected int |
engineUpdate(byte[] in,
int inOff,
int inLen,
byte[] out,
int outOff)
Updates this Cipher with the given bytes.
|
public ElGamal()
This constructor only internally is used for initializing an ElGamal Cipher.
Applications should not call this constructor to get an ElGamal Cipher; they
should call one of the Cipher.getInstance
factory methods
instead, e.g.:
Cipher elGamal = Cipher.getInstance("ElGamal/ECB/PKCSPadding");
Cipher.getInstance(java.lang.String)
protected byte[] engineUpdate(byte[] in, int inOff, int inLen)
doFinal
/ is called.engineUpdate
in class javax.crypto.CipherSpi
in
- the input data as byte arrayinOff
- the start position in the input arrayinLen
- the number of bytes that should be processed, starting at
inOff
null
since no output is produced by this methodCipherSpi.engineUpdate(byte[], int, int)
protected int engineUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff)
doFinal
/ is called.engineUpdate
in class javax.crypto.CipherSpi
in
- the input data as byte arrayinOff
- the start position in the input arrayinLen
- the number of bytes that should be processed, starting at
inOff
out
- the byte array to which to write the result; ignoredoutOff
- the start position in the output array; ignoredjavax.crypto.ShortBufferException
- never thrownCipherSpi.engineUpdate(byte[], int, int, byte[], int)
protected int engineGetBlockSize()
engineGetBlockSize
in class javax.crypto.CipherSpi
protected byte[] engineGetIV()
null
, because this cipher does not use an
IV.engineGetIV
in class javax.crypto.CipherSpi
null
.protected int engineGetOutputSize(int inputLen)
engineGetOutputSize
in class javax.crypto.CipherSpi
protected java.security.AlgorithmParameters engineGetParameters()
engineGetParameters
in class javax.crypto.CipherSpi
protected void engineInit(int opmode, java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
Before a cipher object is ready for data processing, it has to be
initialized according to the desired cryptographic operation, which is
specified by the opmode
parameter (either ENCRYPT_MODE or
DECRYPT_MODE, or WRAP_MODE or UNWRAP_MODE).
The key either will be a ElGamalPrivateKey or a ElGamalPublicKey, depending on the specific cryptographic operation to be performed.
Applications shall use the corresponding init
method of
javax.crypto.Cipher
for provider independently initializing an
ElGamal cipher.
engineInit
in class javax.crypto.CipherSpi
opmode
- Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE or Cipher.WRAP_MODE or
Cipher.UNWRAP_MODEkey
- an instance of an ElGamal PublicKey or ElGamal PrivateKeyrandom
- source of randomnessjava.security.InvalidKeyException
- if the key is invalid (not a valid ElGamal key), or if
PKCS1Padding is used and the key is not appropriate for the
block type, or if a private key is tried to be used for an
encryption operation or a public key is tried to be for a
decryption operationprotected void engineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Before a cipher object is ready for data processing, it has to be
initialized according to the desired cryptographic operation, which is
specified by the opmode
parameter (either ENCRYPT_MODE or
DECRYPT_MODE, or WRAP_MODE or UNWRAP_MODE).
The key either will be a ElGamalPrivateKey or a ElGamalPublicKey, depending on the specific cryptographic operation to be performed.
Applications shall use the corresponding init
method of
javax.crypto.Cipher
for provider independently initializing an
ElGamal cipher.
engineInit
in class javax.crypto.CipherSpi
opmode
- Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE or Cipher.WRAP_MODE or
Cipher.UNWRAP_MODEkey
- an instance of an ElGamal PublicKey or ElGamal PrivateKeyparams
- algorithm parametersrandom
- source of randomnessjava.security.InvalidAlgorithmParameterException
- if the parameters are invalidjava.security.InvalidKeyException
- if the key is invalid (not a valid ElGamal key), or if
PKCS1Padding is used and the key is not appropriate for the
block type, or if private key is tried to be used for an
encryption operation or a public key is tried to be for a
decryption operationprotected void engineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Before a cipher object is ready for data processing, it has to be
initialized according to the desired cryptographic operation, which is
specified by the opmode
parameter (either ENCRYPT_MODE or
DECRYPT_MODE, or WRAP_MODE or UNWRAP_MODE).
The key either will be a ElGamalPrivateKey or a ElGamalPublicKey, depending on the specific cryptographic operation to be performed.
Applications shall use the corresponding init
method of
javax.crypto.Cipher
for provider independently initializing an
ElGamal cipher.
engineInit
in class javax.crypto.CipherSpi
opmode
- Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE or Cipher.WRAP_MODE or
Cipher.UNWRAP_MODEkey
- an instance of a ElGamal PublicKey or ElGamal PrivateKeyparams
- algorithm parameters that may be used for OAEP paddingrandom
- source of randomnessjava.security.InvalidAlgorithmParameterException
- if the parameters are invalidjava.security.InvalidKeyException
- if the key is invalid (not a valid ElGamal key), or if
PKCS1Padding is used and the key is not appropriate for the
block type, or if private key is tried to be used for an
encryption operation or a public key is tried to be for a
decryption operationprotected void engineSetMode(java.lang.String mode) throws java.security.NoSuchAlgorithmException
For PKCS#1v1.5 padding this might be "ECB" (automatic block type selection)
or the padding block type ("0" or "1" for a private key operation, and "2"
for a public key operation.
engineSetMode
in class javax.crypto.CipherSpi
mode
- the transformation mode ("ECB" or PKCS#1v1.5 block type ("0","1"
or "2")java.security.NoSuchAlgorithmException
protected void engineSetPadding(java.lang.String padding) throws javax.crypto.NoSuchPaddingException
engineSetPadding
in class javax.crypto.CipherSpi
padding
- the padding scheme for this ElGamal cipherjavax.crypto.NoSuchPaddingException
- if the requested padding algorithm is not supported, or cannot
be supported (because, for instance, required parameters are
not available)protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Applications shall use the corresponding doFinal
method of
javax.crypto.Cipher
for provider independently doing the data
en/decryption.
The data to be processed is given in an input byte array. Beginning at
inputOffset
, only the first inputLen
bytes are
en/decrypted. The result is returned as an output byte array.
engineDoFinal
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinputOffset
- the offset indicating the start position within the input byte
arrayinputLen
- the number of bytes to be processedjavax.crypto.BadPaddingException
- if a padding problem occursjavax.crypto.IllegalBlockSizeException
Cipher.doFinal()
,
CipherSpi.engineDoFinal(byte[], int, int)
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Applications shall use the corresponding doFinal
method of
javax.crypto.Cipher
for provider independent doing the data
en/decryption.
The data to be processed is given in an input byte array. Beginning at
inputOffset
, only the first inputLen
bytes are
en/decrypted. The result is stored in the given output byte array,
beginning at outputOffset
. The number of bytes stored in this
byte array are returned.
engineDoFinal
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinputOffset
- the offset indicating the start position within the input byte
arrayinputLen
- the number of bytes to be processedoutput
- the byte array for holding the resultoutputOffset
- the offset indicating the start position within the output byte
array to which the en/decrypted data is writtenjavax.crypto.ShortBufferException
- if the given output buffer is too small for holding the resultjavax.crypto.BadPaddingException
- if a padding problem occursjavax.crypto.IllegalBlockSizeException
Cipher.doFinal()
,
CipherSpi.engineDoFinal(byte[], int, int)