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
Joined: Aug 24, 2012
Posts: 19
posted
0
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
Joined: Aug 24, 2012
Posts: 19
posted
0
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.
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
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
Joined: Aug 24, 2012
Posts: 19
posted
0
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.
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.