This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Security and the fly likes Problem with decryption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Problem with decryption" Watch "Problem with decryption" New topic
Author

Problem with decryption

Damodara Reddy Gosula
Greenhorn

Joined: Dec 25, 2011
Posts: 5
Hi,

I am using IBMJCECCA provider. Encrypting text and writing it to MQ and retrieving it on another machine and trying to decrypt.
When I print the value, I do not see anything. But when I check for length of the decrypted string, I see correct length. encrypt and decrypt methods return byte[] using which I am constructing string through new String(bytes). I have even tried passing various character sets to new String(bytes, charset) and it doesn't work. I'm clueless on what is happening here. I have done encryption and decryption on same system (tried separately for both machines) and it works. That confirms, there is no issue with accessing the keys.

Any suggestions or thoughts that could show some pointer would be of great help!

Thanks,
Damodara Reddy
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
new String(bytes).

As a rule of thumb, you should never use new String(byte[]) or String.getBytes(). In this day and age of heterogenous hardware and software, always be explicit about the character encoding. What's more, encrypted data is binary data, not character data - it can't be stored as a string at all (unless you converted it to character data via something like base-64).

When I print the value, I do not see anything.

What does this mean - how are you trying to print it, and where to? Post a relevant code excerpt.


Ping & DNS - my free Android networking tools app
Damodara Reddy Gosula
Greenhorn

Joined: Dec 25, 2011
Posts: 5
I got it working now with your suggestion by changing getBytes and new String methods.

Thanks a lot!

Regards,
Damodara Reddy
Damodara Reddy Gosula
Greenhorn

Joined: Dec 25, 2011
Posts: 5
Hi Ulf,

Wow, I have changed all my getBytes and new String to have a charset and it works now.

Thanks a lot!

Regards,
Damodara Reddy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with decryption
 
Similar Threads
Java AES/CBC/PKCS7Padding missing one part of decrypt code
Encryption of long strings
Could I have broken the law by using SunJCE?!!
Java Cryptography "Input length (with padding) not multiple of 8 bytes "
Excel file gets corrupted when decrypting in weblogic 10.3