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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

RSA decryption using block cipher

843811Mar 29 2007 — edited Mar 30 2007
Hi everybody,

I'am getting stuck around a decryption problem. It is my first time (since one month) I work in java cryptography - and even in cryptography at all.
Well, I made two programs (2 java applet) :
- The first one compute a MD5 hash code of a specified file. Then this hash code is signed with a private key thanks to a X509 certificate, ensuring data integrity (MD5 hash code) and authenticity (signature). This signature is stored in a file with extension .sig.
- The second one simply read the .sig. Then it decrypts the signature thanks to the same certificate (providing the public key). Hence I will be able to read the crypted MD5 hash code in clear.

The problem is that I don't manage to decrypt the signature successfully. Indeed, I sign the MD5 hash code with the algorithm "MD5withRSA", the only one which seems suitable for my case (I want to crypt/decrypt with RSA).
On the other side, when I try to decrypt the signature, this latter is too long : the .sig file has 217 bytes ! So when I pass all this content in a buffer, this one is too long for decryption (with RSA algorithm which works only with blocks of 128 bytes). I managed to have a look at how "block cipher" works including padding. I even found a bit of java code to crypt a long message in multipart. But in my case, I am interested for decryption in multi block. The signature was made in one block (called stream cipher).
My question is : How to do a decryption of a long message with RSA in multi block ?

I try a "debug" code (see below) and I have always the same error : "too much data for RSA block". And yet, I read only 1 byte !!
byte[] decryptedBytes;
			for (int i = 0, j = 0; i < sig.length; i++) {
				if ((decryptedBytes = cipher.update(sig, i, 1)) == null)
					continue;
				else {
					System.out.println(new String(decryptedBytes));
					System.arraycopy(decryptedBytes, 0, plainText, j, decryptedBytes.length);
					j += decryptedBytes.length;
				}		
			}
Thanks for your explanations.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2007
Added on Mar 29 2007
10 comments
523 views