Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

trouble decrypting AES from C# (unsigned byte vs signed byte issue)

843811Apr 6 2009 — edited Apr 7 2009
I am trying to decrypt something which was encrypted in C# and I am getting a BadPadding exception, so I started digging a bit deeper and I found that the byte array that C# is using to encrypt is different than the byte array that java is using to decrypt (Note: both byte arrays are generated from a Hex String). This is the byte array that is passed into the SecretKeySpec constructor.

After stepping through the Hex string to byte array conversion, I found that the byte array differed in places where the hex was something like "B3". This should convert to 179 (as is does in c#), but since there are no unsigned bytes in java, I get -77.

So my question is, I am essentially screwed? Is there any way of getting around this (short of changing the key to not use any hex greater than the Byte.MAX_VALUE)?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2009
Added on Apr 6 2009
3 comments
494 views