Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decryption returning wrong value

 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to decrypt a value using a key stored in a keystore. It's not throwing any exceptions but the "decrypted" value is wrong.

It's spitting out things like: [B@1befab0

This is what I've got.



Any ideas?
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After banging on this for some time, I'm still getting basically the same result with significantly different code.



Outputs: [B@10ef90c

There's somethign fundamental I'm missing here...
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok yup it was fundamental, duh, I was printing a byte[]. lol

But unfortunately the problem is not truly solved. By using the following I converted the byte[] to a String and printed it, but I'm still getting the wrong values.



Now it's outputting:

???L ?A??=?@+?A?h?B???F?
be??????4?????6w???>(???i?&?>?{d?ib)+?es?m??E'??4 T/?????_?
i]??v<\???g?RN?d?/?}?N?+w+a??L???-?8???a??eS???6?*?
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's just the standard way of outputting an array of bytes. The code you've written uses the toString() method of an object to convert it to a String for display, but since arrays don't implement that method, you get the default toString() method of the Object class. Which produces something which starts with the class name ("[B" for byte array) followed by something which sort of represents the object's address. This isn't particularly useful if you expected it to tell you something about the array's contents, because it doesn't do that.

If you want something more meaningful (e.g. something which actually tells you what bytes are in the array) then you'll have to write that code yourself. Or if perhaps you meant to convert that byte array to a String, on the grounds that it actually encodes some text, then



would be the way to do that.
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see you've already figured out what I was saying.

But I don't understand your code. It looks like you're encrypting something and producing an array of bytes, but then when you decrypt you don't decrypt the whole thing, you try to decrypt only part of it. I'm no security expert but I wouldn't expect that to work.

Although it's possible I didn't understand what you were trying to do (see the part about not being an expert).
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I'm not encrypting anything, I am doing a Base64 decode before decrypting. Then I believe the value translates to a DERObject that encapsulates the actual content. I try to extract the content, decrypt it, and display it.
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if line 6 (un-redacted) is supposed to represent encrypted data in some way, then yes, it must have had something done to it to convert the raw bytes into readable text. Perhaps that was Base-64 encoding, but I don't think that has anything to do with the actual process which produced that encrypted data.

I guess that Base-64 is the most likely thing to have been used, but you'd have to check with whoever gave you that encrypted data.

 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the un-redacted encrypted value ...

MIHuBgkqhkiG9w0BBwaggeAwgd0CAQAwgdcGCSqGSIb3DQEHATAKBggqhkiG9w0DBICBvcs6iLO2VGfU7KzJmpU0y5lBsRYAs1tOdZKW6fmJ4XXQUgUyl7rcYUGSa5hu+XfbAFGRHwdLS4LSClP34srZ8aF8KtxXxdYbvxZ7s5xjnleHN8GBneh1ocoofaXLWmoFUa/WS47oQXGY80jSJ/Dm1B28Pt+VerKQtkr8sTRoSwtXWf5RuspfCGFvMddea2xuO5PX+14A+/8VfYuCRjjxMOMWE5suKfBunQICws86QkewfqxbTmOVKsB7kgXKag==

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "==" at the end indicates that it is indeed base-64 encoded.
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After days of sticking with it... here is the solution. The problem was apparently confusion between Base64 from two different packages.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic