Hi.
I have a question and requires immediate attention. The problem is the following.
I have a palm application that I have set up to send a http post request using the INetLib API from palm. Now the information that I am posting are encrypted characters that get encrypted on the client side. However, when we view this data in the servlet we have generated to insert this data in the sql table it doesn't seem to recognize some of these encrypted characters. Some of the characters that the servlet doesn't recognize are shown as ? character.
One of the reasons this may be happeing is because java I believe uses 16 bit unicode character set. Now the encryption that occurs use 64 bit encryption. Does anyone know if this may be causing the problem. And if it isn't what needs to be done to rectify the problem? Thanks for your help.
Here goes:
To encode:
//////////////////////////
// Convert the byte array into one big string
byte[] bytes = // YOUR DATA IN A BYTE ARRAY
Object send = null;
String asciiTemp = null;
int asciiTempLength = 0;
StringBuffer hexEncoded = new StringBuffer();
try {
for( int byteCounter = 0; byteCounter < bytes.length; byteCounter++ ) {
asciiTemp = Integer.toHexString((int)b
asciiTempLength = asciiTemp.length();
if( asciiTempLength > 2 ) {
asciiTemp = asciiTemp.substring(asciiT
}
else if( asciiTempLength == 1 ) {
asciiTemp = "0"+asciiTemp;
}
hexEncoded.append(asciiTem
}
}
catch( Exception e ) {
e.printStackTrace();
}
contentType = "text/plain";
send = hexEncoded.toString();
//////////////////////////
To transmit from the servlet:
//////////////////////////
// Write a text stream
System.out.println("Writin
OutputStream outStream = response.getOutputStream()
PrintWriter out = new PrintWriter(outStream);
out.write((String)send);
out.flush();
outStream.flush();
out.close();
outStream.close();
//////////////////////////
To decode back into a byte array
//////////////////////////
URL request = new URL("http...YOUR URL");
URLConnection connection = request.openConnection();
// Get the response
connection.setDoInput(true
InputStream inStream = connection.getInputStream(
InputStreamReader inr = new InputStreamReader(inStream
BufferedReader br = new BufferedReader(inr);
int size = 0;
String data = br.readLine();
br.close();
inr.close();
inStream.close();
// Reconstruct the byte array from the string
StringTokenizer byteTokenizer = new StringTokenizer(data, ":");
bytes = new byte[byteTokenizer.countTo
int byteCount = 0;
while( byteTokenizer.hasMoreToken
//bytes[byteCount] = Byte.parseByte(byteTokeniz
bytes[byteCount] = (byte)Integer.parseInt(byt
byteCount++;
}
System.out.println("Data retrieved: "+byteCount+" bytes");
System.out.println("Reques
URL request = new URL(newURL);
URLConnection connection = request.openConnection();
//////////////////////////