Package gnu.crypto.cipher

Provides a basic API for using symetric-key block cipher algorithms.

See: Description

Package gnu.crypto.cipher Description:

Provides a basic API for using symetric-key block cipher algorithms.

Package overview

The following diagram shows the important classes participating in this package:

Here is a simple example of how to use the AES cipher. It transforms the plaintext to the ciphertext, and the ciphertext back to the plaintext, using the AES in electronic codebook mode with no padding. Note also the classes for cipher modes and padding schemes for more complex constructions.

IBlockCipher cipher = CipherFactory.getInstance("AES");
Map attributes = new HashMap();
attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(16));
attributes.put(IBlockCipher.KEY_MATERIAL, key_bytes);

cipher.init(attributes);
int bs = cipher.currentBlockSize();
for (int i = 0; i + bs < pt.length; i += bs)
  {
    cipher.encryptBlock(pt, i, ct, i);
  }

for (int i = 0; i + bs < cpt.length; i += bs)
  {
    cipher.decryptBlock(ct, i, cpt, i);
  }
Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.