All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gnu.crypto.cipher.package.html Maven / Gradle / Ivy

The newest version!





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);
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy