|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.me.security.Cipher
This is the base class for all cipher operations. To use a specific cipher implementation do the following:
- get an instance of the implementation
- initialize the cipher with: mode, key, opt. initialisation vector (IV) and SecureRandom object.
- feed the cipher with the data to be en-/decrypted via the cipher.update() method
- call cipher.doFinal() to close the operation
Note: the blocksize parameter in the transformation string is not supported.
For example:
Cipher cipher = Cipher.getInstance( "AES/CBC/NoPadding" ); cipher.init(Cipher.ENCRYPT_MODE, key_, IV_, null ); bytesEncrypted = cipher.update(buffer, 0, buffer.length, encryptedBuffer, 0); bytesEncrypted = cipher.doFinal(buffer, 0, buffer.length, encryptedBuffer, 0);
Field Summary | |
protected int |
chainingMode
Cipher chaining mode, either MODE_ECB or MODE_CBC. |
static int |
DECRYPT_MODE
Constant specifying decryption mode. |
static int |
ENCRYPT_MODE
Constant specifying encryption mode. |
protected byte[] |
iv
IV as byte array |
protected int |
mode
Cipher mode, either ENCRYPT_MODE or DECRYPT_MODE. |
protected static int |
MODE_CBC
Constant for CBC mode. |
protected static int |
MODE_ECB
Constant for ECB mode. |
Constructor Summary | |
protected |
Cipher(int blockSize)
Constructor for use by cipher implementations. |
Method Summary | |
protected void |
cryptBlock(byte[] input,
int inputOffset,
byte[] output,
int outputOffset)
Encrypt one block. |
byte[] |
doFinal(byte[] input)
Encrypt the given data performing padding and return the result in a new byte array. |
int |
doFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Encrypt the given data performing final padding operations. |
protected void |
extractIV(int mode,
Object params,
SecureRandom random)
|
int |
getBlockSize()
Return the block size in byte for this cipher, e.g. 8 for IDEA. |
static Cipher |
getInstance(String algorithm)
Returns a cipher implementation. |
CryptoBag |
getIV()
Returns the IV as a cryptobag object or null if no IV is available. |
abstract int[] |
getKeyLength()
Return the valid key lengths for this cipher. |
void |
init(int mode,
CryptoBag key)
Initialize this cipher. |
abstract void |
init(int mode,
CryptoBag key,
Object params,
SecureRandom random)
Initialize this cipher. |
static void |
register(String name,
String clazz)
Registers a Cipher implementation dynamically. for e.g.:
register("MyCipher", "mypackage.MyCipher");
The registered cipher can afterwards be instantiated with the getInstance ("MyCipher"); method |
protected String |
setMode(String mode)
Set the cipher chaining mode. |
protected String |
setPadding(String padding)
Set the cipher padding mode. |
String |
toString()
Return a String representation of the cipher. |
int |
update(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Encrypt the input data storing it in the output array. |
protected int |
updateInternal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset,
boolean doFinal)
This is method performs the actual en-/decipher opertion. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
protected static final int MODE_ECB
protected static final int MODE_CBC
protected int mode
protected byte[] iv
protected int chainingMode
Constructor Detail |
protected Cipher(int blockSize)
Method Detail |
public CryptoBag getIV()
public int getBlockSize()
public abstract int[] getKeyLength()
public final void init(int mode, CryptoBag key) throws CryptoException
init(mod, key, null, null);
.public abstract void init(int mode, CryptoBag key, Object params, SecureRandom random) throws CryptoException
public int update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws CryptoException
protected int updateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, boolean doFinal) throws CryptoException
input
- input datainputOffset
- offset from which on the input data will be processedinputLen
- length of the input data that will be processedoutput
- the processed input dataoutputOffset
- doFinal
- flag indicates whether this method was invoked from Cipher.update or Cipher.doFinalCryptoException
- is thrown if an error occurs during cipher operationprotected void cryptBlock(byte[] input, int inputOffset, byte[] output, int outputOffset) throws CryptoException
public int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws CryptoException
public byte[] doFinal(byte[] input) throws CryptoException
protected String setMode(String mode) throws CryptoException
protected String setPadding(String padding) throws CryptoException
protected void extractIV(int mode, Object params, SecureRandom random) throws CryptoException
public String toString()
toString
in class Object
public static Cipher getInstance(String algorithm) throws CryptoException
ObjectID
mapped to such a
transformation string via the ASN1 class. For example, the string could be "AES/CBC/PKCS5Padding". Symmetric ciphers support
ECB and CBC modes, NoPadding and PKCS5Padding. Any error (algorithm not available, invalid transformation string) causes a CryptoException.
Cipher cipher = Cipher.getInstance();
algorithm
- the algorithm name plus mode and padding stringCryptoException
- if the requested mode or padding schema cannot be set or the requested algorithm implementation is not availablepublic static void register(String name, String clazz)
register("MyCipher", "mypackage.MyCipher");
getInstance
("MyCipher"); methodname
- alias of the cipherclazz
- pakcage.classname
|
This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |