• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with decryption

 
Damodara Reddy Gosula
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Damodara Reddy Gosula
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic