First of all, let me say that I know this isn't supposed to be done. But I'm being forced into this ;) Money is the root of all evil.
I'm encrypting with RSA. My data is more than one block long. I can post code if necessary but I'll try to show pseudo code first as I will have to obscure some data to post code, and I don't think its necessary anywho.
Can someone tell me what I'm doing wrong? Everything works fine when I do a smaller chunk ( one block or less ) and use doFinal(). But my multi-block implementation isn't working. Details below.
Code:
//key objects and variables
cipher rsaCipher
int cipherBlockSize
byte[] plainText
int lengthOfPlainText
int remainingBytesToProcess = lengthOfPlainText;
while ( remaingBytesToProcess > cipherBlockSize )
{
byte[] block = getTheNextSetOfBlockSizeBytesFrom plainText;
//THIS DOESN'T RETURN ANYTHING? API SAYS IT DOES BUT I NEVER GET
//ANYTIING RETURNED BY UPDATE WITH THIS RSA CIPHER
rsaCipher.update( block);
}
//EXITING THE BLOCK I SHOULD HAVE JUST A REMAINING CHUNK, LESS THAN BLOCK SIZE
block = remainintBytes //NOTE ITS LESS THAN A FULL BLOCK SIZE;PROBLEM?
//THIS NEXT LINE BLOWS UP WITH THE STACK TRACE INCLUDED BELOW
byte[] cipherText = rsaCipher.doFinal( block );
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block
at org.bouncycastle.jce.provider.JCERSACipher.engineD oFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(DashoA12275)
at com.blackdog.testing.encryption.JFSmartCardTest.ma in(JFSmartCardTest.java:105)