Java Reference
In-Depth Information
The Bouncy Castle Crypto API
An additional feature that is currently unavailable in J2ME CLDC is the Java Cryptography Extension
(JCE). The JCE is a set of packages providing a framework for encryption, key generation and key
agreement, and Message Authentication Code (MAC) algorithms. It supports encryption for symmetric,
asymmetric, block, and stream ciphers.
The Bouncy Castle Crypto API, which is available from http://www.bouncycastle.org , supports the
following features:
• A clean-room implementation of the JCE 1.2.1
• A lightweight cryptography API in Java
• A provider for the JCE and JCA
• Generators for Version 1 and Version 3 X.509 certificates
Because a complete implementation of the JCE is too big for the J2ME CLDC platform, we will focus
on the lightweight API available for the J2ME CLDC platform. It is specially developed for
circumstances in which the complete API and the integration of the JCE aren't required.
The lightweight API provides the following subset of the JCE:
AsymmetricBlockCipher
BlockCipher
BufferedBlockCipher
BufferedAsymmetricBlockCipher
BufferedStreamCipher
Digest
KeyAgreement
Mac
PBE
StreamCipher
For example, these tools let you cipher a password that needs to be transferred over a network for user
authorization. Listing 10.9 shows an example of how a String can be ciphered using a private key
with the Blowfish encryption algorithm that is part of the Bouncy Castle Crypto API. Encryption and
decryption are performed entirely in the methods encryptText() and decryptText() in order
to providing an easy mechanism for adopting to your own implementations. Figure 10.4 shows the
original and the encrypted text in the MIDlet.
Figure 10.4. The Blowfish MIDlet showing decrypted text on the left and the encrypted
on the right.
Listing 10.9 BlowfishMidp.java —The BlowfishMidp Sample Source Code
import java.io.*;
import java.lang.*;
 
 
 
Search WWH ::




Custom Search