aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 39547
    
  27
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 - updated with new look and Ping home screen widget
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
Excel file gets corrupted when decrypting in weblogic 10.3
Java Cryptography "Input length (with padding) not multiple of 8 bytes "
Could I have broken the law by using SunJCE?!!
Encryption of long strings
Java AES/CBC/PKCS7Padding missing one part of decrypt code