?
Solved

unable to store encrypted characters through servlet

Posted on 2001-06-06
8
Medium Priority
?
252 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:Arod
[X]
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
8 Comments
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6162047
Hmm,

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.

Regards,
Igor Bazarny
Brainbench MVP for Java 1
www.brainbench.com
0
 
LVL 2

Expert Comment

by:dhymes
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?
0
 

Author Comment

by:Arod
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.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 2

Expert Comment

by:dhymes
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?
0
 

Author Comment

by:Arod
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!
0
 
LVL 3

Expert Comment

by:chrisos
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.

Regards,

Chrisos.
0
 

Author Comment

by:Arod
ID: 6163928
If you can do that Chrisos I would appreciate it!
0
 
LVL 3

Accepted Solution

by:
chrisos earned 600 total points
ID: 6164058
Arod,

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;
          }
          hexEncoded.append(asciiTemp+":");
     }
}
catch( Exception e ) {
     e.printStackTrace();
}
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);
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.countTokens()];
int byteCount = 0;
while( byteTokenizer.hasMoreTokens() ) {
     //bytes[byteCount] = Byte.parseByte(byteTokenizer.nextToken());
     bytes[byteCount] = (byte)Integer.parseInt(byteTokenizer.nextToken(), 16);
     byteCount++;
}
System.out.println("Data retrieved: "+byteCount+" bytes");
System.out.println("Request = "+newURL);
URL request = new URL(newURL);
URLConnection connection = request.openConnection();

////////////////////////////////////////////////
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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