Cipher initialization - when?

I have server code which creates data encrypted with a 3DES key and signed with an RSA key constantly (it's basically some custom authentication service). In the original implementation, I had only one static Cipher object of each type (3DES encryption, 3DES decryption, RSA signing), to which access was synchronized, and which were all initialized with the respective key before an encryption or signing operation.

Now I wanted to improve performance and get rid of the synchronization, so I created a dynamic pool of those Cipher objects, which basically creates a set of Cipher objects for a request thread. This part works fine so far, so I got rid of synchronization.

But I also wanted to remove unnecessary intializations, so initialized each cipher only once at creation time, 3DES and RSA. As a result, I got problems with the 3DES ciphers (I'm using IAIK), where I could encrypt data, and when I decrypted it, the first 8 bytes were all of a sudden different (or corrupted, maybe). With the RSA ciphers I didn't have any problem like that.

The javadoc of "Cipher" isn't really specific enough for me. Is it correct that in principle a Cipher object has to be initialized with its key only once, when it's being created, and never again? If so, my problems would probably mean there's some bug in the IAIK provider.

[1355 byte] By [marcelschoena] at [2007-11-27 7:50:49]
# 1

> Is it correct that in principle a Cipher

> object has to be initialized with its key only once,

> when it's being created, and never again?

I'm pretty sure it can be initialized as many times as you want.

As for the rest of your problem, without seeing code it is impossible to diagnose your problem.

sabre150a at 2007-7-12 19:31:53 > top of Java-index,Security,Cryptography...
# 2
Yes, it can be initialized as many times as I want, but my question is, does it have to be initialized any time I use it? Because that's what I currently have to do with those 3DES ciphers. And since initialization also may take some time, I'd want to avoid it if possible.
marcelschoena at 2007-7-12 19:31:53 > top of Java-index,Security,Cryptography...
# 3

> Yes, it can be initialized as many times as I

> want, but my question is, does it have to be

> initialized any time I use it? Because that's what I

> currently have to do with those 3DES ciphers. And

> since initialization also may take some time, I'd

> want to avoid it if possible.

No problem with the SunJCE provider - I have DESede Cipher code out there that has been running unchanged for the last 5 years with the Cipher objects only initialized once but used over and over for weeks/months at a time.

sabre150a at 2007-7-12 19:31:53 > top of Java-index,Security,Cryptography...