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!

Java to C# to Java, RSA, PKCS #1

843811Mar 25 2009 — edited Mar 26 2009
Hi,

I have a Java server that generates a RSA public/private key (
KeyPairGenerator.getInstance("RSA")
), the public key is sent to a C# client and it uses it to encrypt some data to be sent back to the server.
However, the decryption on the server-wise fails because it appeared that the same data generated random outputs (from C#).
Then I came across: http://blogs.msdn.com/shawnfa/archive/2006/01/05/509444.aspx

Basically, RSA uses random padding on the input bytes.

In C#, i am using
rsaCryptoServiceProvider.Encrypt(clearData, false)
(therefore PKCS #1 v1.5)

In Java, I tried to use
Cipher.getInstance("RSA/ECB/PKCS1PADDING")
but it fails with the following exception:
javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes.
Any idea how to fix the Java-side (or C# side)

Thx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2009
Added on Mar 25 2009
13 comments
5,838 views