Java – Reusing passwords (preventing initialization)

Reusing passwords (preventing initialization)… here is a solution to the problem.

Reusing passwords (preventing initialization)

I’m working on improving our encryption performance. We need to stream encrypted video, so we encrypt each frame (h.264 NALU to be exact) and send it over the network. We can’t stream PAL videos on Android this way.

We are using AES (AES/CBC/PKCS7Padding), and we use the same key and IV for each frame in the session. I know, it’s not very secure, but I wasn’t there when it was implemented and it’s too late to change it. So, for each frame, we call Cipher.init() with the same parameters (key and IV) and then just doFinal. Is it possible to somehow prevent this and reuse initialized Cipher objects?

Or is there a better video streaming algorithm than AES? We are using SpongyCaSTLe. Is there anything faster? Or should we rewrite it in the NDK using OpenSSL?

Solution

Calling init() only once and then calling doFinal() repeatedly is exactly what we did, and it improved throughput by more than 50%.

Related Problems and Solutions