Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert byte array to string and back not the same???

807580Jun 27 2010 — edited Jun 27 2010
Hello there! Can someone please help me out with a dilemma...

I encrypted a string, and the cipher.doFinal that I used to encrypt returned a byte[]. I did
String encrypted = new String(cipher.doFinal(....));
Then when decrypting the same string I did this:
cipher.doFinal(encrypted.getBytes()...);
At this point, the cipher class complained saying that it's corrupted. But if I keep it in a byte array, it works fine:
byte[] encrypted = cipher.doFinal(....);
cipher.doFinal(encrypted...);
How can I safely store the byte[] in a string and convert it back perfectly... The reason why I need it in a string is because I have to send the encrypted data to a server over HTTP as a string.

Thank you!

Edited by: Arrowx7 on Jun 27, 2010 12:53 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 25 2010
Added on Jun 27 2010
3 comments
813 views