Before you start
With the ever present concern over security, software applications must consider how to secure confidential data. A mobile application is not immune from privacy concerns. In fact, mobile devices and their software applications have special considerations given that most people carry these devices wherever they go.
This tutorial provides an overview of how to encrypt application-related data in a Java 2 Micro Edition (J2ME) application (MIDlet). The tutorial begins with a brief introduction to data encryption. As encryption is not a topic for the faint of heart, this section is rather brief, and focuses specifically on the open source encryption API written by the Legion of Bouncy Castle. The topic concludes by developing a MIDlet to demonstrate encrypting and decrypting of text strings.
One problem inherent to most mobile devices is the limited amount of memory. Although Bouncy Castle and other encryption libraries offer an abundance of functionality, there is a price. As with most any library you use, only a small portion of the code is typically needed by your application. One common way to eliminate unused code, and at the same time make it more challenging to reverse engineer an application, is to use a Java obfuscator. I'll introduce the open source obfuscator, ProGuard. This addresses everything from downloading and installing, to configuring the J2ME Wireless Toolkit to use ProGuard. The final section in this tutorial compares MIDlet JAR file sizes, with and without obfuscation.
To run the samples in this tutorial, you'll need the following software tools:
- The Java Development Kit (JDK)
- The Wireless Toolkit (WTK)
- Bouncy Castle
- ProGuard
See Software prerequisites for information on downloading, installing, and configuring these software tools.

