unable to store encrypted characters through servlet

Posted on 2001-06-06
Last Modified: 2013-11-24
 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.
Question by:Arod
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1

Expert Comment

by:Igor Bazarny
ID: 6162047

Can you post a bit of code? I believe that you problem is that you don't need characters at all, you simply need bytes, and attempt to read characters leads to conversion from bytes to unicode chars. Or maybe you have different encodings on client end server side.

Igor Bazarny
Brainbench MVP for Java 1

Expert Comment

ID: 6162193
Those encrypted characters need to be of a specific type prior to sending them accross the wire since it is binary data. What are you using to pass the data over the wire?

Author Comment

ID: 6162240
All that I'm doing is sending an Http post request. The purpose of the post is to assign a variable the value of the encrypted message. The encrypted message is encoded with a lot of funny characters due to the 64 bit encoding. The variable containing the encrypted message is sent to the servlet which makes a jdbc connection to a sql database. This is so that we can store the encrypted message in a table. The variable with the encryption message is retrieved using the req.getParameter() function and assigned to a string.
 The palm code was written in c. We are encrypting the message using the DES algorithm with mode OFB. Let me know if this helps.
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.


Expert Comment

ID: 6162342
Those encrypted characters need to be of a specific type prior to sending them accross the wire since it is binary data. What are you using to pass the data over the wire?

Author Comment

ID: 6162411
What do you mean by the type of the encrypted characters? The variable in which the encrypted characters are stored is a pointer to character which is basically a string. This is how it is sent through the http post!

Expert Comment

ID: 6163117
I have come accross a similar problem over the last few days.  I had to transmit class files along a stream from a servlet to an application.  

The way I dealt with it was to convert the byte array into hex characters and transmit these characters (0-f), it isn't plesant!  I know it is not an elegent solution as you need to encode, transmit then decode and the transimssion duration will be increased due to the crap encoding!

If you are interesed I can post the code for you.



Author Comment

ID: 6163928
If you can do that Chrisos I would appreciate it!

Accepted Solution

chrisos earned 200 total points
ID: 6164058

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)bytes[byteCounter]);
          asciiTempLength = asciiTemp.length();
          if( asciiTempLength > 2 ) {
               asciiTemp = asciiTemp.substring(asciiTemp.length()-2);
          else if( asciiTempLength == 1 ) {
               asciiTemp = "0"+asciiTemp;
catch( Exception e ) {
contentType = "text/plain";
send = hexEncoded.toString();


To transmit from the servlet:


// Write a text stream
System.out.println("Writing output");
OutputStream outStream = response.getOutputStream();
PrintWriter out = new PrintWriter(outStream);


To decode back into a byte array


URL request = new URL("http...YOUR URL");
URLConnection connection = request.openConnection();

// Get the response
InputStream inStream = connection.getInputStream();
InputStreamReader inr = new InputStreamReader(inStream);
BufferedReader br = new BufferedReader(inr);
int size = 0;
String data = br.readLine();

// Reconstruct the byte array from the string
StringTokenizer byteTokenizer = new StringTokenizer(data, ":");
bytes = new byte[byteTokenizer.countTokens()];
int byteCount = 0;
while( byteTokenizer.hasMoreTokens() ) {
     //bytes[byteCount] = Byte.parseByte(byteTokenizer.nextToken());
     bytes[byteCount] = (byte)Integer.parseInt(byteTokenizer.nextToken(), 16);
System.out.println("Data retrieved: "+byteCount+" bytes");
System.out.println("Request = "+newURL);
URL request = new URL(newURL);
URLConnection connection = request.openConnection();


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question