|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.motorola.iden.crypto.Cipher
This class provides the functionality of a cryptographic cipher for encryption and decryption.
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:
(in the latter case, provider-specific default values for the mode and padding scheme are used). For example, the following is a valid transformation:
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
[CipherSpi]
Field Summary | |
static int |
CBC
Constant used to initialize cipher to CBC mode. |
static int |
CFB
Constant used to initialize cipher to CFB64 mode. |
static int |
CFB128
Constant used to initialize cipher to CFB128 mode. |
static int |
DECRYPT_MODE
Constant used to initialize cipher to decryption mode. |
static int |
ECB
Constant used to initialize cipher to ECB mode. |
static int |
ENCRYPT_MODE
Constant used to initialize cipher to encryption mode. |
static int |
OFB
Constant used to initialize cipher to OFB64 mode. |
static int |
OFB128
Constant used to initialize cipher to OFB128 mode. |
static int |
PKCS1V15
Constant used to initialize padding to PKCS#1v15; |
static int |
PKCS5
Constant used to initialize padding to PKCS#5; |
static int |
PRIVATE
Constant used to initialize public key operation. |
static int |
PUBLIC
Constant used to initialize public key operation. |
Constructor Summary | |
protected |
Cipher(CipherSpi cipherSpi)
Creates a Cipher object. |
Method Summary | |
byte[] |
doFinal()
Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialized. |
byte[] |
doFinal(byte[] input)
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. |
byte[] |
doFinal(byte[] input,
int offset,
int len)
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. |
java.lang.String |
getAlgorithm()
Returns the algorithm name of this Cipher object.
|
int |
getBlockSize()
Returns the block size (in bytes). |
static Cipher |
getInstance(java.lang.String transformation)
Generates a Cipher object that implements the specified
transformation.
|
byte[] |
getIV()
Returns the initialization vector (IV) in a new buffer. |
void |
init(int opmode,
Key key)
Initializes this cipher with a key. |
void |
init(int opmode,
Key key,
AlgorithmParameterSpec params)
Initializes this cipher with a key and a set of algorithm parameters. |
byte[] |
update(byte[] input)
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part. |
byte[] |
update(byte[] input,
int offset,
int len)
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
public static final int ECB
public static final int CBC
public static final int CFB
public static final int OFB
public static final int CFB128
public static final int OFB128
public static final int PKCS5
public static final int PKCS1V15
public static final int PUBLIC
public static final int PRIVATE
Constructor Detail |
protected Cipher(CipherSpi cipherSpi)
cipherSpi
- the instance of an algorithm which implements CipherSpi.Method Detail |
public static final Cipher getInstance(java.lang.String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException
Cipher
object that implements the specified
transformation.
If the default provider package supplies an implementation of the
requested transformation, an instance of Cipher
containing
that implementation is returned.
transformation
- the name of the transformation, e.g.,
DES/CBC/PKCS5Padding, or DES.The following table list all supported cipher algorithms, modes, and paddings.
ALGORITM | MODE | PADDING |
---|---|---|
DES | ECB;CBC;CFB;OFB | PKCS5Padding |
DESede | ECB;CBC;CFB;OFB | PKCS5Padding |
AES | ECB;CBC;CFB;OFB | PKCS5Padding |
RC5 | ECB;CBC;CFB;OFB | PKCS5Padding |
ARC4 | ----- | ----- |
RSA | ECB | PKCS1v15Padding |
NoSuchAlgorithmException
- if the specified transformation is
not available in the default provider package.NoSuchPaddingException
- if transformation
contains a padding scheme that is not available.public final java.lang.String getAlgorithm()
Cipher
object.
This is the same name that was specified in one of the
getInstance
calls that created this Cipher
object..
Cipher
object.public final int getBlockSize()
public final byte[] getIV()
This is useful in the case where a random IV was created, or in the context of password-based encryption or decryption, where the IV is derived from a user-supplied password.
public final void init(int opmode, Key key) throws InvalidKeyException, InvalidAlgorithmParameterException
The cipher is initialized for one of the following two operations:
encryption or decryption, depending
on the value of opmode
.
If this cipher requires any algorithm parameters that cannot be
derived from the given key
, the underlying cipher
implementation is supposed to generate the required parameters itself.
opmode
- the operation mode of this cipher (this is one of
the following:
ENCRYPT_MODE
, DECRYPT_MODE
)key
- the keyInvalidKeyException
- if the given key is inappropriate for
initializing this cipher, or if this cipher is being initialized for
decryption and requires algorithm parameters that cannot be
determined from the given key, or if the given key has a keysize that
exceeds the maximum allowable keysize (as determined from the
configured jurisdiction policy files).InvalidAlgorithmParameterException
- if algorithmparameters
are needed to init this cipher.public final void init(int opmode, Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException
The cipher is initialized for one of the following two operations:
encryption or decryption,depending
on the value of opmode
.
opmode
- the operation mode of this cipher (this is one of the
following: ENCRYPT_MODE
,
DECRYPT_MODE
)key
- the encryption keyparams
- the algorithm parametersInvalidKeyException
- if the given key is inappropriate for
initializing this cipher, or its keysize exceeds the maximum allowable
keysize (as determined from the configured jurisdiction policy files).InvalidAlgorithmParameterException
- if the given algorithm
parameters are inappropriate for this cipher,
or this cipher is being initialized for decryption and requires
algorithm parameters and params
is null, or the given
algorithm parameters imply a cryptographic strength that would exceed
the legal limits (as determined from the configured jurisdiction
policy files).public final byte[] update(byte[] input) throws java.lang.IllegalStateException
The bytes in the input
buffer are processed, and the
result is stored in a new buffer.
If input
has a length of zero, this method returns
null
.
input
- the input bufferjava.lang.IllegalStateException
- if this cipher is in a wrong state
(e.g., has not been initialized)public final byte[] update(byte[] input, int offset, int len) throws java.lang.IllegalStateException
The first inputLen
bytes in the input
buffer, starting at inputOffset
inclusive, are processed,
and the result is stored in a new buffer.
If inputLen
is zero, this method returns
null
.
input
- the input bufferoffset
- the offset in input
where the input
startslen
- the input lengthjava.lang.IllegalStateException
- if this cipher is in a wrong state
(e.g., has not been initialized)public final byte[] doFinal() throws java.lang.IllegalStateException, IllegalBlockSizeException, BadPaddingException
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.
A call to this method resets this cipher object to the state
it was in when previously initialized via a call to init
.
That is, the object is reset and available to encrypt or decrypt
(depending on the operation mode that was specified in the call to
init
) more data.
java.lang.IllegalStateException
- if this cipher is in a wrong state
(e.g., has not been initialized)IllegalBlockSizeException
- if this cipher is a block cipher,
no padding has been requested (only in encryption mode), and the total
input length of the data processed by this cipher is not a multiple of
block sizeBadPaddingException
- if this cipher is in decryption mode,
and (un)padding has been requested, but the decrypted data is not
bounded by the appropriate padding bytespublic final byte[] doFinal(byte[] input) throws java.lang.IllegalStateException, IllegalBlockSizeException, BadPaddingException
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.
A call to this method resets this cipher object to the state
it was in when previously initialized via a call to init
.
That is, the object is reset and available to encrypt or decrypt
(depending on the operation mode that was specified in the call to
init
) more data.
input
- the input bufferjava.lang.IllegalStateException
- if this cipher is in a wrong state
(e.g., has not been initialized)IllegalBlockSizeException
- if this cipher is a block cipher,
no padding has been requested (only in encryption mode), and the total
input length of the data processed by this cipher is not a multiple of
block sizeBadPaddingException
- if this cipher is in decryption mode,
and (un)padding has been requested, but the decrypted data is not
bounded by the appropriate padding bytespublic final byte[] doFinal(byte[] input, int offset, int len) throws java.lang.IllegalStateException, IllegalBlockSizeException, BadPaddingException
The first inputLen
bytes in the input
buffer, starting at inputOffset
inclusive, 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.
A call to this method resets this cipher object to the state
it was in when previously initialized via a call to init
.
That is, the object is reset and available to encrypt or decrypt
(depending on the operation mode that was specified in the call to
init
) more data.
input
- the input bufferoffset
- the offset in input
where the input
startslen
- the input lengthjava.lang.IllegalStateException
- if this cipher is in a wrong state
(e.g., has not been initialized)IllegalBlockSizeException
- if this cipher is a block cipher,
no padding has been requested (only in encryption mode), and the total
input length of the data processed by this cipher is not a multiple of
block sizeBadPaddingException
- if this cipher is in decryption mode,
and (un)padding has been requested, but the decrypted data is not
bounded by the appropriate padding bytes
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |