开发者

AES Encryption Issue between Java and C# .Net

I've looked at countless examples on the web and in this forum and I can't find my answer.

I have a Java client that successfully encrypts and decrypts data. I have a .Net client that successfully encrypts and decrypts data.

I put the .Net version up as a web service. I encrypt some data in the java client and send 开发者_Go百科it to the .Net web service. I get: --Padding is invalid and cannot be removed.--

So I make sure I'm using the same encoding, IV, Key, everything. The only think I can figure is that I'm sending a byte array to the service. When I spit out the array from the java client and compare it to the array that arrives at the service, as you would expect, the array at the service is different in that it's cast as an unsigned byte array. Here are the two arrays:

[-47 17 -27 -32 -101 54 -93 47 85 -83 -31 -102 53 -125 115 -14]

[209 17 229 224 155 54 163 47 85 173 225 154 53 131 115 242]

So I'm guessing that this is causing the issue. How can I get around this? None of the Rijndael implementations accept signed byte arrays. Is there a conversion I'm missing?

Thanks for any help. I'm ready to gouge my brain out through my arse. ST

EDIT - After reviewing the code I found my error. I had to copy some data and started at the wrong index. Arrrgggghhhhhhh!

Sorry to trouble.


You've got the same actual data in both cases - it's just that Java doesn't support unsigned bytes. If each platform can decrypt its own data, and you've got the same data generated by both platforms, it's hard to see how they could tell the difference.

My guess is that you're doing something differently on the .NET side. We'll need to see code to know for sure.

What happens if you try to decrypt the exact same data in the .NET client which can decrypt data? I suggest you create a small console app which just tries to decrypt a file. Make your .NET server save whatever data it's given to the file and then try to decrypt it as normal. Then run the console app on the file. Report the results here, and we'll try to help you make sense of them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜