hi, im in a bit of rush here to get things done... can anyone show me how to convert a string to byte without changing it's content? just cloning or mirroring the value? meaning... String st = "AbCdE"; and i need it to be converted to byte as... byte bt = AbCdE; using getBytes() on the string wont do as it convert it's value... the problem im having is when passing a byte value thru http, it is converted to string... so back at the servlet i need it to be byte again. please help. thanks in advance, shin.
Joined: Feb 05, 2003
I haven't got time to check this but have you tried getBytes("US-ASCII")? Obviously assuming that everything you have is a valid ASCII character?
Joined: Aug 19, 2002
i need the encrypted data in byte exactly the way it was 'in-appearence' of the string for decryption process after receiving it at the servlet... if i use getBytes() the encrypted file wont look the same anymore, wont it? original text... (String) text = "IAMWHOIAM" text being signed with private key into byte format digital cert.. (Byte) cText= [B@84aee8b; the text being appended to url sending over to servlet... http://localhost:8080/midp/hits?cText=[B@84aee8b now back to servlet, calling getParameter("cText") will return... (String) cText = [B@84aee8b; AND NOW i need it to be byte value = [B@84aee8b so i could decrypt it using the public key located on the server side... but instead, doing cText.getBytes() returns value [B@c5c7331 ... which is not what it was before sending, so i cant decrypt it properly anymore, can i? hope this explains my problem (i hope this question aint too stupid not to be bothered ;-).. thanks guys, ryan
Joined: Dec 19, 2002
Originally posted by Ryan Crow: text being signed with private key into byte format digital cert.. (Byte) cText= [B@84aee8b; the text being appended to url sending over to servlet... http://localhost:8080/midp/hits?cText=[B@84aee8b now back to servlet, calling getParameter("cText") will return... (String) cText = [B@84aee8b;
Heh. You forgot to convert your byte array back to a String. [B@c5c7331 simply indicates a byte array stored at location c5c7331 in memory. Here's pseudocode for what you want to do... 1. Get the original string 2. Convert the original string to bytes 3. append signature/encrypt bytes 4. Convert bytes back to a string (now encrypted) 5. Send string to receiver over http -- receiver starts here 6. Get encrypted string from request 7. Convert encrypted string to bytes 8. decrypt bytes/digital signature 9. convert bytes back to original string Translating into Java-like: 2. byte bytes=original.getBytes(encoding); 3. (encryption code goes here) 4. String parm=new String(bytes, encoding); 6. msg=request.getParameter("cText"); 7. byte encrypted=msg.getBytes(encoding); 8. (decryption code goes here) 9. String msg=new String(encrypted, encoding);
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.