views:

165

answers:

1
+2  Q: 

Java to Python RSA

I'm trying to encrypt a string from Java to Python, using the library Bouncy Castle J2ME on the client side and Python M2Crypto on the other.

Everything is pretty good, I can decrypt it properly, but the padding is the issue.

The M2Crypto lib gives me (as far as I can tell) only these Padding schemes: no_padding = 3 pkcs1_padding = 1 sslv23_padding = 2 pkcs1_oaep_padding = 4

While the bouncy castle J2ME only provides: NoPadding OAEPWithAndPadding PKCS5Padding SSL3Padding

So, I can use NoPadding between both, but then the strings that get generated after decryption are filled with jumbled characters.

I'd really like to get the padding sorted out, but I don't know how to convert between padding schemes / if that's even possible.

Please help me figure this out, it's killing me!

+1  A: 

I'm not familiar with Bouncy Castle but I guess you somehow use RSAEngine which implements AsymmetricBlockCipher thus you should be able to use PKCS1 or not?

And there also seems to be OAEP support, which given the right parameters should also work.

jitter
I guess I was. I posted this after hours of tinkering in desperation, and lo and behold it was something rather simple.It turns out, if I use the string "RSA/ECB/PKCS1Padding" with the "BC" provider, it can be read by python using PKCS1. The ECB is required, otherwise there's junk characters everywhere.Also, I had to make sure the key was in DER format, and read it with the X509EncodedKeySpec for it to read. DER = PEM minus the header (----BEGIN ...), and base64 decoded.
Crowe T. Robot