Java Reference
In-Depth Information
int length = (int)hc.getLength();
ciphertext = new byte[length];
in.read(ciphertext);
in.close();
hc.close();
}
catch (IOException ioe) {
Alert a = new Alert("Exception", ioe.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mTextBox);
}
// Decrypt the server response.
String hex = new String(ciphertext);
byte[] dehexed = HexCodec.hexToBytes(hex.toCharArray());
byte[] deciphered = new byte[dehexed.length];
mInCipher.processBytes(dehexed, 0, dehexed.length, deciphered, 0);
String decipheredString = new String(deciphered);
Alert a = new Alert("Response", decipheredString, null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mTextBox);
}
// Normally you would probably read keys from resource files
// in the MIDlet suite JAR, using the getResourceAsStream()
// method in Class. Here we just use hard-coded values that match
// the hard-coded values in StealthServlet.
private byte[] getInKey() {
return "Incoming MIDlet key".getBytes();
}
private byte[] getOutKey() {
return "Outgoing MIDlet key".getBytes();
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
}
When the user invokes the Send command, StealthMIDlet encrypts the user's message
with its outgoing cipher. It then encodes the ciphertext as hexadecimal text in preparation for
sending it to the servlet. The user's name and the ciphertext are packaged into a GET URL and
sent to the server. Additionally, StealthMIDlet keeps track of a cookie that is used for session
tracking. If the server sends back a session ID cookie, it is saved in StealthMIDlet 's mSession
member variable. The saved cookie is sent with each subsequent request. This allows the server
Search WWH ::




Custom Search