h31591 s 00159/00536/00690 d D 1.3 97/12/09 15:24:40 luehe 4 3 c rm ,* e s 00002/00003/01224 d D 1.2 97/10/10 12:42:05 luehe 3 1 c fixed getProvider javadocs e s 00000/00000/00000 d R 1.2 97/10/09 09:58:13 Codemgr 2 1 c SunPro Code Manager data about conflicts, renames, etc... c Name history : 1 0 security/JCE1.2/earlyaccess/javax.crypto.Cipher.html e s 01227/00000/00000 d D 1.1 97/10/09 09:58:12 luehe 1 0 c date and time created 97/10/09 09:58:12 by luehe e u U f e 0 t T I 1
D 3 E 3 I 3 D 4 E 4 I 4 E 4 E 3D 4 All Packages Class Hierarchy This Package Previous Next IndexE 4 I 4 All Packages Class Hierarchy This Package Previous Next Index E 4
java.lang.Object | +----javax.crypto.Cipher
This class must be implemented by a provider who supports the above cryptographic services and wishes to register them with the Java Security Framework. E 4
In order to create a Cipher object, the application calls the
Cipher's getInstance
method, and passes the name of the
requested transformation to it. Optionally, the name of a provider
may be specified.
A transformation is a string that describes the operation (or set of operations) to be performed on the given input, to produce some output. A transformation always includes the name of a cryptographic algorithm (e.g., DES), and may be followed by a feedback mode and padding scheme. A transformation is of the form: D 4 algorithm or algorithm/mode/padding (in the former case, defaults are used for mode and padding). For example, DES/CBC/PKCS5Padding represents a valid transformation.
A provider may supply a separate class for each combination of algorithm/mode/padding, or may decide to provide more generic classes representing sub-transformations corresponding to algorithm or algorithm/mode, whose mode and/or padding schemes can be set using engineSetMode and engineSetPadding, respectively.
For example, a provider may supply a subclass of Cipher
that implements DES/ECB/PKCS5Padding, one that implements
DES/CBC/PKCS5Padding, one that implements
DES/CFB/PKCS5Padding, and yet another one that implements
DES/OFB/PKCS5Padding.
A different provider may implement a class for each of the above modes
(i.e., one class for ECB, one for CBC, one for CFB,
and one for OFB), one class for the PKCS5Padding scheme,
and a generic DES class (subclass of Cipher
), into
which the above mode and padding classes can be "plugged into", using the
engineSetMode
and engineSetPadding
methods.
The algorithm for instantiating a Cipher
object
(using one of the getInstance
methods) when a
transformation of the form algorithm is given is as follows:
Cipher
for the specified algorithm. If the answer is YES, instantiate this
class, for whose mode and padding scheme default values (as supplied by
the provider) are used.
If the answer is NO, throw a NoSuchAlgorithmException
exception.
The algorithm for instantiating a Cipher
object when a
transformation of the form algorithm/mode/padding is given is as
follows:
Cipher
for the specified algorithm/mode/padding transformation.
If the answer is YES, instantiate this class and return it to the user.
If the answer is NO, go to the next step.
Cipher
for the sub-transformation algorithm/mode.
If the answer is YES, instantiate this class, and call
engineSetPadding(padding)
on the new instance, before
returning it to the user.
If the answer is NO, go to the next step.
Cipher
for the sub-transformation algorithm.
If the answer is YES, instantiate this class, and call
engineSetMode(mode)
and
engineSetPadding(padding)
on the new instance, before
returning it to the user.
If the answer is NO, throw a NoSuchAlgorithmException
exception.
The methods of Cipher
are divided into two groups:
engineEncryptInit
is called by init
.
When requesting a block cipher in stream cipher mode (e.g.,
DES
in CFB
or OFB
mode), the user may
optionally specify the number of bits to be
processed at a time, by appending this number to the mode name as shown in
the "DES/CFB8/NoPadding" and "DES/OFB32/PKCS5Padding"
transformations. If no such number is specified, a provider-specific default
is used. (For example, the Sun JCE provider uses a default of 64 bits.)
E 4
update
or doFinal
operation, given the input length
inputLen
(in bytes).
Cipher
object that implements the specified
D 4
algorithm, as supplied by the default provider.
E 4
I 4
transformation, as supplied by the default provider.
E 4
Cipher
object that implements the specified
D 4
algorithm, as supplied by the specified provider.
E 4
I 4
transformation, as supplied by the specified provider.
E 4
update
or
doFinal
operation, given the input length
inputLen
(in bytes).
Cipher
object.
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
D 4 public Cipher() E 4 I 4 protected Cipher(CipherSpi cipherSpi, Provider provider, String transformation) E 4I 4
D 4 public static Cipher getInstance(String algorithm) throws NoSuchAlgorithmException, NoSuchPaddingException E 4 I 4 public static final Cipher getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException E 4
Cipher
object that implements the specified
D 4
algorithm, as supplied by the default provider.
E 4
I 4
transformation, as supplied by the default provider.
E 4
D 4 public static Cipher getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException E 4 I 4 public static final Cipher getInstance(String transformation, String provider) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException E 4
Cipher
object that implements the specified
D 4
algorithm, as supplied by the specified provider.
E 4
I 4
transformation, as supplied by the specified provider.
E 4
public final Provider getProvider()
Cipher
object.
Cipher
object, or null if the
provider has not yet been set
E 3
I 3
Cipher
object
E 3
public abstract void engineSetMode(String mode) throws NoSuchAlgorithmException
public abstract void engineSetPadding(String padding) throws NoSuchPaddingException
D 4 public int getBlockSize() E 4 I 4 public final int getBlockSize() E 4
protected abstract int engineGetBlockSize()
D 4 public int getOutputSize(int inputLen) throws IllegalStateException E 4 I 4 public final int getOutputSize(int inputLen) throws IllegalStateException E 4
update
or
doFinal
operation, given the input length
inputLen
(in bytes).
This call takes into account any unprocessed (buffered) data from a
previous update
call, and padding.
The actual output length of the next update
or
doFinal
call may be smaller than the length returned by
this method.
protected abstract int engineGetOutputSize(int inputLen) throws IllegalStateException
update
or doFinal
operation, given the input length
inputLen
(in bytes).
This call takes into account any unprocessed (buffered) data from a
previous update
call, and padding.
The actual output length of the next update
or
doFinal
call may be smaller than the length returned by
this method.
D 4 public byte[] getIV() E 4 I 4 public final byte[] getIV() E 4
This is useful in the case where a random IV has been created (see init), or in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.
protected abstract byte[] engineGetIV()
This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.
D 4 public void init(int opmode, Key key) throws IllegalStateException, InvalidKeyException E 4 I 4 public final void init(int opmode, Key key) throws InvalidKeyException E 4
The cipher is initialized for encryption or decryption, depending on
E 4
the value of opmode
.
I 4
If this cipher requires an initialization vector (IV), it will get it from a system-provided source of randomness. The random IV can be retrieved using getIV. This behaviour should only be used in encryption mode, however. When initializing a cipher that requires an IV for decryption, the IV (same IV that was used for encryption) must be provided explicitly as a parameter, in order to get the correct result.
Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher, and initializing it. E 4
ENCRYPT_MODE
or DECRYPT_MODE
)
D 4 public void init(int opmode, Key key, SecureRandom random) throws IllegalStateException, InvalidKeyException E 4 I 4 public final void init(int opmode, Key key, SecureRandom random) throws InvalidKeyException E 4
The cipher is initialized for encryption or decryption, depending on
E 4
the value of opmode
.
D 4
If this cipher (including its underlying feedback or padding scheme)
requires any random bytes, it will get them from random
.
E 4
I 4
If this cipher requires an initialization vector (IV), it will get
it from random
. The random IV can be
retrieved using getIV.
This behaviour should only be used in encryption mode, however.
When initializing a cipher that requires an IV for decryption, the IV
(same IV that was used for encryption) must be provided explicitly as a
parameter, in order to get the correct result.
Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher, and initializing it. E 4
ENCRYPT_MODE
or DECRYPT_MODE
)
protected abstract void engineInit(int opmode, Key key, SecureRandom random) throws IllegalStateException, InvalidKeyException
opmode
.
If this cipher (including its underlying feedback or padding scheme)
requires any random bytes, it will get them from random
.
ENCRYPT_MODE
or DECRYPT_MODE
)
D 4 public void init(int opmode, Key key, AlgorithmParameterSpec params) throws IllegalStateException, InvalidKeyException, InvalidAlgorithmParameterException E 4 I 4 public final void init(int opmode, Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException E 4
The cipher is initialized for encryption or decryption, depending on
E 4
the value of opmode
.
I 4
Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher, and initializing it. E 4
ENCRYPT_MODE
or DECRYPT_MODE
)
D 4 public void init(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws IllegalStateException, InvalidKeyException, InvalidAlgorithmParameterException E 4 I 4 public final void init(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException E 4
The cipher is initialized for encryption or decryption, depending on
E 4
the value of opmode
.
If this cipher (including its underlying feedback or padding scheme)
requires any random bytes, it will get them from random
.
I 4
Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher, and initializing it. E 4
ENCRYPT_MODE
or DECRYPT_MODE
)
protected abstract void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws IllegalStateException, InvalidKeyException, InvalidAlgorithmParameterException
opmode
.
If this cipher (including its underlying feedback or padding scheme)
requires any random bytes, it will get them from random
.
ENCRYPT_MODE
or DECRYPT_MODE
)
D 4 public byte[] update(byte input[]) throws IllegalStateException E 4 I 4 public final byte[] update(byte input[]) throws IllegalStateException E 4
The bytes in the input
buffer are processed, and the
result is stored in a new buffer.
D 4 public byte[] update(byte input[], int inputOffset, int inputLen) throws IllegalStateException E 4 I 4 public final byte[] update(byte input[], int inputOffset, int inputLen) throws IllegalStateException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, are processed, and the
result is stored in a new buffer.
input
where the input
starts
protected abstract byte[] engineUpdate(byte input[], int inputOffset, int inputLen) throws IllegalStateException
The first inputLen
bytes in the input
buffer, starting at inputOffset
, are processed, and the
result is stored in a new buffer.
input
where the input
starts
D 4 public int update(byte input[], int inputOffset, int inputLen, byte output[]) throws IllegalStateException, ShortBufferException E 4 I 4 public final int update(byte input[], int inputOffset, int inputLen, byte output[]) throws IllegalStateException, ShortBufferException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, are processed, and the
result is stored in the output
buffer.
I 4
If the output
buffer is too small to hold the result,
a ShortBufferException
is thrown. In this case, repeat this
call with a larger output buffer. Use
getOutputSize to determine how big the
output buffer should be.
E 4
input
where the input
starts
output
D 4 public int update(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException E 4 I 4 public final int update(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, are processed, and the
result is stored in the output
buffer, starting at
outputOffset
.
I 4
If the output
buffer is too small to hold the result,
a ShortBufferException
is thrown. In this case, repeat this
call with a larger output buffer. Use
getOutputSize to determine how big the
output buffer should be.
E 4
input
where the input
starts
output
where the result
is stored
output
protected abstract int engineUpdate(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException
The first inputLen
bytes in the input
buffer, starting at inputOffset
, are processed, and the
result is stored in the output
buffer, starting at
outputOffset
.
input
where the input
starts
output
where the result
is stored
output
D 4 public byte[] doFinal() throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4 I 4 public final byte[] doFinal() throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4
Input data that may have been buffered during a previous
update
operation is processed, with padding (if requested)
being applied.
The result is stored in a new buffer.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4
D 4 public int doFinal(byte output[], int outputOffset) throws IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException E 4 I 4 public final int doFinal(byte output[], int outputOffset) throws IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException E 4
Input data that may have been buffered during a previous
update
operation is processed, with padding (if requested)
being applied.
The result is stored in the output
buffer, starting at
outputOffset
.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4 I 4
If the output
buffer is too small to hold the result,
a ShortBufferException
is thrown. In this case, repeat this
call with a larger output buffer. Use
getOutputSize to determine how big the
output buffer should be.
E 4
output
where the result
is stored
output
D 4 public byte[] doFinal(byte input[]) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4 I 4 public final byte[] doFinal(byte input[]) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4
The bytes in the input
buffer, and any input bytes that
may have been buffered during a previous update
operation,
are processed, with padding (if requested) being applied.
The result is stored in a new buffer.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4
D 4 public byte[] doFinal(byte input[], int inputOffset, int inputLen) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4 I 4 public final byte[] doFinal(byte input[], int inputOffset, int inputLen) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, and any input bytes that
may have been buffered during a previous update
operation, are processed, with padding (if requested) being applied.
The result is stored in a new buffer.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4
input
where the input
starts
protected abstract byte[] engineDoFinal(byte input[], int inputOffset, int inputLen) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException
The first inputLen
bytes in the input
buffer, starting at inputOffset
, and any input bytes that
may have been buffered during a previous update
operation,
are processed, with padding (if requested) being applied.
The result is stored in a new buffer.
The cipher is reset to its initial state (uninitialized) after this call.
input
where the input
starts
D 4 public int doFinal(byte input[], int inputOffset, int inputLen, byte output[]) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException E 4 I 4 public final int doFinal(byte input[], int inputOffset, int inputLen, byte output[]) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, and any input bytes that
may have been buffered during a previous update
operation, are processed, with padding (if requested) being applied.
The result is stored in the output
buffer.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4 I 4
If the output
buffer is too small to hold the result,
a ShortBufferException
is thrown. In this case, repeat this
call with a larger output buffer. Use
getOutputSize to determine how big the
output buffer should be.
E 4
input
where the input
starts
output
D 4 public int doFinal(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException E 4 I 4 public final int doFinal(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException E 4
The first inputLen
bytes in the input
buffer, starting at inputOffset
, and any input bytes that
may have been buffered during a previous update
operation,
are processed, with padding (if requested) being applied.
The result is stored in the output
buffer, starting at
outputOffset
.
D 4
The cipher is reset to its initial state (uninitialized) after this call. E 4 I 4
If the output
buffer is too small to hold the result,
a ShortBufferException
is thrown. In this case, repeat this
call with a larger output buffer. Use
getOutputSize to determine how big the
output buffer should be.
E 4
input
where the input
starts
output
where the result
is stored
output
protected abstract int engineDoFinal(byte input[], int inputOffset, int inputLen, byte output[], int outputOffset) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException
The first inputLen
bytes in the input
buffer, starting at inputOffset
, and any input bytes that
may have been buffered during a previous update
operation,
are processed, with padding (if requested) being applied.
The result is stored in the output
buffer, starting at
outputOffset
.
The cipher is reset to its initial state (uninitialized) after this call.
input
where the input
starts
output
where the result
is stored
output
D 4 All Packages Class Hierarchy This Package Previous Next IndexE 4 I 4 All Packages Class Hierarchy This Package Previous Next Index E 4 E 1