You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Supal J Patel <su...@in.ibm.com> on 2006/07/13 13:54:01 UTC

Getting : javax.crypto.ShortBufferException while creating a encrypted database

Hi All,

I am trying to create a encrypted  Derby Db using 
com.ibm.j9.jce.provider.J9JCEProvider.  This JCE provider comes with IBM's 
J9 JRE. I am using J9 JCL Max and this J9 comes with j9jceprov.jar which 
is a JCEProvider.

To debug the problem I downloaded Derby source and successfully set up a 
local development environment. While looking at the source code I found 
that  in org.apache.derby.impl.services.jce.JCECipherProvider class'
public int encrypt(byte[] cleartext, int offset, int length,  byte[] 
ciphertext, int outputOffset) method is throwing this exception. 

I understand that this exception is thrown when  the given output buffer 
is too small to hold the result . Thats why I updated this method as 
attached in Updated_Encrypt_Method.txt to make sure that outbuffer is 
always sufficient.  Now after this change if you check the Debug 
statements printed in attached OutPut.txt  then you will find that length 
of ciphertext array and out put of cipher.getOutputSize(length) is always 
same and its still throwing ShortBufferException. And in that case it 
should not throw this exception. 

For your reference I am also attaching my test class which is 
JDBCTest.java. Please also note that I am using J9 as my JRE.
If I run the same test program with IBM 1.4.2 JRE and use either IBMJCE 
provider (which comes with IBM JRE 1.4.2) or BouncyCastleProvider its 
working fine and I can successfully create the encrypted database.

Can anyone please help me with this strange problem? Is it the problem 
with com.ibm.j9.jce.provider.J9JCEProvider I am using ?



Thanks and Regards,

Supal Patel

Re: Getting : javax.crypto.ShortBufferException while creating a encrypted database

Posted by Sunitha Kambhampati <ks...@gmail.com>.
Supal J Patel wrote:

>
> To debug the problem I downloaded Derby source and successfully set up 
> a local development environment. While looking at the source code I 
> found that  in org.apache.derby.impl.services.jce.JCECipherProvider 
> class'
> public int encrypt(byte[] cleartext, int offset, int length,  byte[] 
> ciphertext, int outputOffset) method is throwing this exception. 

It might be helpful if you can post the derby.log and stack traces for 
the original exception.

>
> I understand that this exception is thrown when  the given output 
> buffer is too small to hold the result . Thats why I updated this 
> method as attached in Updated_Encrypt_Method.txt to make sure that 
> outbuffer is always sufficient. 
>
In this case, I'd expect the caller of the encrypt method to pass the 
ciphertext with correct size.  doFinal is taking the outputOffset, so 
ciphertext size should take of the outputOffset also.

Since you have the development environment already setup, maybe you can 
run this with sane mode. (ant clobber; ant sane; ant all)

 There are actually some assert statements in the encrypt method that 
would throw errors if the ciphertext array was of insufficient size.  
Another thing to try is to print out the parameter values that are 
passed in this method and to print out the stack traces in encrypt when 
the exception is hit.  
      System.out.println("encrypt method called : cleartext = " + 
cleartext.length + " ciphertext = " + ciphertext.length + " offset : " + 
offset + " length : " + length + " outputOffset: "+ outputOffset ); 
When this exception is hit, what is the value of arguments to encrypt 
method ?

 I dont have the j9 jce provider, so cannot try it out to see what could 
be happening.  But maybe someone else on the list can try it out. So 
please post your findings on the list.

Thanks,
Sunitha.