Java Reference
In-Depth Information
Listing 18-5. StealthMIDlet, a Data Encryption MIDlet
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.bouncycastle.crypto.StreamCipher;
import org.bouncycastle.crypto.engines.RC4Engine;
import org.bouncycastle.crypto.params.KeyParameter;
public class StealthMIDlet
extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private TextBox mTextBox;
private String mSession;
private StreamCipher mOutCipher, mInCipher;
public StealthMIDlet() {
mOutCipher = new RC4Engine();
mInCipher = new RC4Engine();
}
public void startApp() {
if (mSession == null) {
// Load the keys from resource files.
byte[] inKey = getInKey();
byte[] outKey = getOutKey();
// Initialize the ciphers.
mOutCipher.init(true, new KeyParameter(outKey));
mInCipher.init(false, new KeyParameter(inKey));
}
mDisplay = Display.getDisplay(this);
if (mTextBox == null) {
mTextBox = new TextBox("StealthMIDlet",
"The eagle has landed", 256, 0);
Search WWH ::




Custom Search